[R] source a script file straight from a subversion repository

Marc Schwartz marc_schwartz at comcast.net
Sat Aug 2 02:42:14 CEST 2008


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