[R] relative referencing for filenames &etc

Greg Tarpinian sasprog474474 at yahoo.com
Tue Feb 28 18:52:11 CET 2006


Thank you both for your helpful suggestions.  My ignorance of R prevents me
from understanding exactly how to

   "...run from a shortcut, appending DATADIR=J:/foo/bar to the 
    command line"

but I assume that Appendix C of "S Programming" will help me there -- I was
unaware of this material when I posted my question.  I was able to success-
fully use the following:

   > Sys.putenv("R_DATADIR"="Z:/.../raw")
   > Sys.getenv("R_DATADIR")
      R_DATADIR 
   "Z:/.../raw" 
   > file.path(Sys.getenv("R_DATADIR"), "RAWDATA.xls")
   [1] "Z:/.../raw/RAWDATA.xls"

Using this type of code, I should be able to "point" R at data and output
directories.  In my industry, programmers are required to save their SAS
log files for auditing purposes, and knowing that R has similar capabilities
is very helpful.

Again, thanks for your help.  Kind regards,


     Greg




--- Prof Brian Ripley <ripley at stats.ox.ac.uk> wrote:

> On Tue, 28 Feb 2006, Uwe Ligges wrote:
> 
> >
> >
> > On Mon, 27 Feb 2006, Greg Tarpinian wrote:
> >
> >> BACKGROUND:
> >> I use SAS on a daily basis and one of its most powerful features in a
> >> production environment is the use of LIBNAME and FILEREF statements, e.g.:
> >>
> >>
> >> PROC PRINTTO LOG = "&LOGDIR.\data processing.log" NEW;
> >> RUN;
> >> PROC IMPORT
> >> 	DATAFILE= "&DATADIR.\blah.xls"
> >> 	OUT = TEMP
> >> 	DBMS = EXCEL REPLACE;
> >>     SHEET = "Sheet1";
> >>     GETNAMES = YES;
> >> RUN;
> >>
> >>
> >> Properly setting up SAS Shortcuts in the WinXP environment, or (say)
> >> the UNIX equivalent of batch files in the UNIX environment will cause
> >> SAS to autoexecute (say) an INIT.SAS file that automatically assigns
> >> the LOGDIR and DATADIR macro variables used above.  This is extremely
> >> convenient because it makes the SAS code more portable from project to
> >> project.
> >>
> >>
> >> MY QUESTION:
> >> Is it possible to use this kind of relative file and directory referencing
> >> from within R?
> >
> > Perhaps you are looking for ?setwd
> 
> Another idea is to use environment variables.  So if in an R function I 
> have
> 
>      xls_file <- file.path(Sys.getenv("DATADIR"), "blah.xls")
> 
> I can R run from a shortcut, appending DATADIR=J:/foo/bar to the command 
> line.
> 
> -- 
> Brian D. Ripley,                  ripley at stats.ox.ac.uk
> Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
> University of Oxford,             Tel:  +44 1865 272861 (self)
> 1 South Parks Road,                     +44 1865 272866 (PA)
> Oxford OX1 3TG, UK                Fax:  +44 1865 272595
>




More information about the R-help mailing list