[R] Is there a way to source from a specific Git repository without hardcoding the location everywhere?
Duncan Murdoch
murdoch.duncan at gmail.com
Thu Sep 27 02:35:00 CEST 2012
On 12-09-26 8:25 PM, Curt Seeliger wrote:
> Folks,
>
> A small group of us are working together to develop a set of R functions
> to support data management and analysis using Eclipse/StatET in a Windows
> environment. We are using Git/EGit for version control. We work within
> our own repository and occasionally push to a common remote location.
>
> I'd like to have the code source files from the 'local' git repository
> without modification, where 'local' could mean c:\yada\ for one person,
> m:\my documents\wetlands\ for another, and l:\foo\bar\sharedRemote\wet\ to
> another user.
>
> The chdir argument to source() has been suggested for similar questions,
> but I have not been able to figure out how this helps without hardcoding
> the location in some manner.
>
> One option is for each repository to have an untracked file which sets the
> local working directory before sourcing another file that actually sources
> the function definitions. This file (projectStart.r below) would be read
> into the R session prior to use, at least during development.
>
> projectStart.r # untracked
> setwd("c:\yada\") # or setwd("L:\foo\bar\sharedRemote\wet\")
> -- this is the only difference among repository locations.
> source("projectStart2.r")
>
> projectStart2.r # tracked
> source("func1.r")
> source("func2.r")
> source("func3.r")
> ...
>
> func1.r # tracked
>
> func2.r # tracked
>
> func3.r # tracked
>
> ...
>
> Is there an easier or better accepted method?
Yes. Use
library(myProject)
where myProject is a package containing all the scripts, written as
functions.
Duncan Murdoch
More information about the R-help
mailing list