An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20120926/ec069b0c/attachment.pl>
Is there a way to source from a specific Git repository without hardcoding the location everywhere?
12 messages · Duncan Murdoch, Hadley Wickham, Daniel Nordlund +2 more
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
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20120926/ed25848c/attachment.pl>
where myProject is a package containing all the scripts, written as functions.
Yes, the eventual fate of these functions is expected to be a package. I'd like the pushed/pulled code to be runable as is without an intermediate step of package creation or gsub()ing hardcoded paths.
You might want to look at load_code in devtools (which is designing
for code stored in packages, but may work for your situation),
otherwise use only relative paths inside your project, and then ensure
people source(, chdir = T) one function that loads everything else.
If your example, all you need to do is
source("path/to/projectStart.r", chdir = T).
Hadley
RStudio / Rice University http://had.co.nz/
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. ...
Yes. Use library(myProject) where myProject is a package containing all the scripts, written as functions.
Yes, the eventual fate of these functions is expected to be a package. I'd like the pushed/pulled code to be runable as is without an intermediate step of package creation or gsub()ing hardcoded paths.
Also, something that Duncan was probably thinking but didn't mention, is that creating a package is really really easy - all you need to do is put your R files in a directory called R and create a description file that says what the package does, who's allowed to use it (the license), who to contact if there are problems (author/maintainer) and what other packages it requires (depends/imports). Hadley
RStudio / Rice University http://had.co.nz/
On 12-09-27 3:31 AM, Hadley Wickham wrote:
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. ...
Yes. Use library(myProject) where myProject is a package containing all the scripts, written as functions.
Yes, the eventual fate of these functions is expected to be a package. I'd like the pushed/pulled code to be runable as is without an intermediate step of package creation or gsub()ing hardcoded paths.
Also, something that Duncan was probably thinking but didn't mention, is that creating a package is really really easy - all you need to do is put your R files in a directory called R and create a description file that says what the package does, who's allowed to use it (the license), who to contact if there are problems (author/maintainer) and what other packages it requires (depends/imports).
I would usually do more than that: I find the R documentation system helpful even when I'm the only user of a package (and there are the prompt* functions for quickly creating it, as well as package.skeleton to set things up at the beginning). Vignettes are a great way to organize and document things that are done via scripts. And if you want to include compiled C or C++ or Fortran code, packages are drastically easier to manage than other approaches. Duncan Murdoch
I would usually do more than that: I find the R documentation system helpful even when I'm the only user of a package (and there are the prompt* functions for quickly creating it, as well as package.skeleton to set things up at the beginning). Vignettes are a great way to organize and document things that are done via scripts. And if you want to include compiled C or C++ or Fortran code, packages are drastically easier to manage than other approaches.
Me too - but I'd never write Rd by hand ;) instead relying on roxygen2 to automate as much of the process as possible. I also find that having the code and documentation co-located makes it easier to keep in sync. But my point main was that it's very easy to start a package - and you don't need every component of a package for it to be useful. In fact the point of packages is to make your life easier - it's a set of conventions to follow so that you don't have to invent everything from scratch. Once you have conventions, then it's easy to use tools that others have written for performing common operations. And in R, you have several philosophies of tools to choose from. Hadley
RStudio / Rice University http://had.co.nz/
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20120927/9969da5c/attachment.pl>
-----Original Message----- From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of Curt Seeliger Sent: Wednesday, September 26, 2012 5:51 PM To: r-help at r-project.org Subject: Re: [R] Is there a way to source from a specific Git repository without hardcoding the location everywhere? Duncan Murdoch <murdoch.duncan at gmail.com> wrote on 09/26/2012 05:35:00 PM:
... 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. ...
Yes. Use library(myProject) where myProject is a package containing all the scripts, written as functions.
Yes, the eventual fate of these functions is expected to be a package. I'd like the pushed/pulled code to be runable as is without an intermediate step of package creation or gsub()ing hardcoded paths. Thanks for the quick reply, cur -- Curt Seeliger, Data Ranger Raytheon Information Services - Contractor to ORD seeliger.curt at epa.gov 541/754-4638
Curt,
each user could set a PROJECT_PATH environment variable on the local machine, and then project script files could contain the code
setwd(Sys.getenv(c('PROJECT_PATH')))
Hope this is helpful,
Dan
Daniel Nordlund
Bothell, WA USA
Curt: Well, if you want to peer a bit more, you might wish to have a look at http://inlinedocs.r-forge.r-project.org/ . Same philosophy as Roxygen_x (keep docs together with code, generate Rd files automatically therefrom) but takes a different approach. Perhaps worth noting for both cases is that thermodynamics applies(you can't get something from nothing): The simplicity you gain from "standardization" when combining docs with code entails a certain loss of flexibility in the organization and content of the .Rd files (which you can, of course, always then manually edit by hand) You can decide which, if either, of the packages strikes the right balance for you. Cheers, Bert On Thu, Sep 27, 2012 at 8:45 AM, Curt Seeliger
<Seeliger.Curt at epamail.epa.gov> wrote:
I would usually do more than that: I find the R documentation system helpful even when I'm the only user of a package ...
Me too - but I'd never write Rd by hand ;) instead relying on roxygen2 ... But my point main was that it's very easy to start a package - and you don't need every component of a package for it to be useful. ...
Thank you both for the ideas. Since the eventual fate of the code is a
package, it makes sense to start taking baby steps in that direction. That
a package can be created without all the features is encouraging.
And roxygen2 is suggested, over roxygen and roxygen3. I only have time to
peek down this rabbit hole right now, but I have to admit it's starting to
look like it may be fun.
Thanks again,
cur
--
Curt Seeliger, Data Ranger
Raytheon Information Services - Contractor to ORD
seeliger.curt at epa.gov
541/754-4638
[[alternative HTML version deleted]]
______________________________________________ R-help at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Bert Gunter Genentech Nonclinical Biostatistics Internal Contact Info: Phone: 467-7374 Website: http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20120927/660d6e10/attachment.pl>
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20120927/1c4256ba/attachment.pl>