Hi there, Ive tried trawling the lists for a solution but I could not find any matches. I am typing up all my code on a Linux machine and I call this other script file from my script file using source("foo.r"). Now sometimes i access my folder from my Windows machine at work (the files are on dropbox). But of course my windows machine would not understand the linux path name. Is there any syntax for searching the file system for "foo.r" from within the script file that I am writing? I know that I can always change the working directory to the one where the script file is stored but is there any other way? Thanks! Abhisek Banerjee [[alternative HTML version deleted]]
Gabor Grothendieck
2010-Aug-29 20:25 UTC
[R] Finding source files automatically within a script
On Sun, Aug 29, 2010 at 1:13 PM, Abhisek <shieks at gmail.com> wrote:> Hi there, > > Ive tried trawling the lists for a solution but I could not find any > matches. ?I am typing up all my code on a Linux machine and I call this > other script file from my script file using source("foo.r"). ?Now sometimes > i access my folder from my Windows machine at work (the files are on > dropbox). ?But of course my windows machine would not understand the linux > path name. > > Is there any syntax for searching the file system for "foo.r" from within > the script file that I am writing? ?I know that I can always change the > working directory to the one where the script file is stored but is there > any other way? > > Thanks! > Abhisek Banerjee >You could (1) use file.exists to successively check specific paths. It will return FALSE if the path does not exist letting you skip over the bad paths. See ?file.exists You could alternately (2) set an option in the your .Profile on both machines (?options, ?getOption, ?Startup), (3) outside of R set up environment variables on both machines reading them in with Sys.getenv or (4) set up configuration files (e.g. a file with just one line giving the path to the file) which you read in from your home directory e.g., readLines("~/.myconfig") Note that ~ works from within R even on Windows and forward slashes work in Windows filenames from within R as well as backslashes. -- Statistics & Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.com