[R] source a script file straight from a subversion repository
Steven McKinney
smckinney at bccrc.ca
Sat Aug 2 03:38:54 CEST 2008
Thanks to Duncan Murdoch and Marc Schwartz for their
excellent help.
As we don't yet have the apache http: interface to svn
running yet, 'svn export' is the access mechanism.
As I don't want to leave stale files lying around,
or clobber a local file should there be one with
the same name, R's tempfile() and Marc's ideas
work very well.
## Get a local copy of the file from the
## version control repository svn on myrepo.xxx.org
tempfilename <- tempfile()
shellcmd <-
paste("svn export ",
"svn://myrepo.xxx.org/opt/svn/repos/",
"Projects/SMcode/tags/v1.0/SMfuns.R ",
tempfilename,
sep = "")
system(shellcmd)
if (file.exists(tempfilename) ) {
source(tempfilename)
unlink(tempfilename)
} else {
stop("Can not get copy of SMfuns.R")
}
I can wrap this in a function where
needed as Marc suggests.
Thanks again for the help
Best
Steve McKinney
> -----Original Message-----
> From: Marc Schwartz [mailto:marc_schwartz at comcast.net]
> Sent: Fri 8/1/2008 5:42 PM
> To: Steven McKinney
> Cc: r-help at r-project.org
> Subject: Re: [R] source a script file straight from a subversion repository
>
> on 08/01/2008 06:49 PM Steven McKinney wrote:
> > Hi useRs
> >
> > I'm trying to figure out how to source
> > an R script file straight from a subversion
> > repository, without having to put a copy
> > of the script into the local working directory.
> >
> > Has anyone done this?
> >
> > Something such as
> >
> > source(file = paste("svn://myrepo.xxx.org/opt/svn/repos/",
> > "/Projects/SMcode/tags/v1.0/SMfuns.R",
> > sep = ""))
> >
> > though this does not work.
> >
> > Perhaps I need a connection of some sort
> > instead of just a text string for the
> > file argument?
> >
> > I'm not sure if this can work, and have not
> > found an example searching through the archives
> > and help manuals as yet.
> >
> > If anyone has done this and can offer any
> > tips I'd appreciate it.
>
> The problem is that the files in a svn repo are not stored as directly
> addressable files. They are stored in a database, typically using the
> Berkeley DB, but will use FSFS if NFS is to be used. You can't get to
> them without going through the svn interface (either CLI or one of the
> GUIs or something like Trac).
>
> Thus, you either have to do a checkout ('svn co'), which means an entire
> directory tree or sub-tree, or do an export ('svn export') to access a
> single file. In the former case, you get a 'working copy' of the tree
> which can be managed by svn. In the latter case, you get a single file,
> but one that is not under svn control.
>
> To do what you want, some variation of:
>
> 1. 'svn export' the file
> 2. source() the file
> 3. delete the file
>
> would be required. You can wrap all of that in a function to shield the
> individual steps, but at minimum, the 'svn export' would be required to
> get to the single file locally. You can call the 'svn export' using the
> R system() function, thus doing it all within an R session.
>
> So something like:
>
> SVNSource <- function(FullPathToSVNFileName)
> {
> cmd <- paste("svn export", FullPathToSVNFileName)
> system(cmd)
> source(basename(FullPathToSVNFileName))
> file.remove(basename(FullPathToSVNFileName))
> }
>
> The basename() R function returns just the file name, stripping the path
> component.
>
> Thus, given your example:
>
> SVNSource("svn://myrepo.xxx.org/opt/svn/repos/Projects/SMcode/tags/v1.0/SMfuns.R")
>
> should hopefully work, but I would test it all to be sure.
>
> This presumes that the command:
>
> $ svn export
> svn://myrepo.xxx.org/opt/svn/repos/Projects/SMcode/tags/v1.0/SMfuns.R
>
> works from the CLI to begin with to get the file locally.
>
> HTH,
>
> Marc Schwartz
More information about the R-help
mailing list