[R] relative referencing for filenames &etc
Prof Brian Ripley
ripley at stats.ox.ac.uk
Tue Feb 28 14:25:49 CET 2006
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