Bryan Hanson
2007-Oct-26 02:49 UTC
[R] Accessing scripts in a different directory on a Mac
Hi all. A question for knowledgeable folks using R on an Intel Mac running OS X 10.4.10 For ease of maintenance, I have broken a large R script into a main script which ?oversees? things by calling other scripts, using ?source?. Let?s call the secondary scripts ?sub-scripts.? I?d like for the sub-scripts to reside in a different directory (again, for ease of maintenance, and so I can access them from many other directories). I?ve looked all over the documentation about paths and filenames, but I?m having trouble deciding which of the many functions is the one I need. As a more specific example, my main script currently contains source(?test.R?) and I need to do something like source(path"test.R"). Ideally, I'd like to specify path early in the file one time, and have it apply automatically later. Stuff in the documentation only seems to tease! Thanks in advance, Bryan
consider something along the lines of:>scriptdir <- '/path/to/scripts/">source(paste(scriptdir,'subscript.r',sep=''))alternatively, you could try:>workdir <- getwd() >scriptdir <- '/path/to/scripts/">setwd(scriptdir) >source('subscript.r') >setwd(workdir)cheers, tim On 10/26/07, Bryan Hanson <hanson at depauw.edu> wrote:> Hi all. A question for knowledgeable folks using R on an Intel Mac running > OS X 10.4.10 > > For ease of maintenance, I have broken a large R script into a main script > which ?oversees? things by calling other scripts, using ?source?. Let?s > call the secondary scripts ?sub-scripts.? > > I?d like for the sub-scripts to reside in a different directory (again, for > ease of maintenance, and so I can access them from many other directories). > I?ve looked all over the documentation about paths and filenames, but I?m > having trouble deciding which of the many functions is the one I need. > > As a more specific example, my main script currently contains > source(?test.R?) and I need to do something like source(path"test.R"). > > Ideally, I'd like to specify path early in the file one time, and have it > apply automatically later. > > Stuff in the documentation only seems to tease! > > Thanks in advance, Bryan > > ______________________________________________ > 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. >-- Tim Calkins 0406 753 997