s-news
[Top] [All Lists]

Re: setwd() analogue

To: Iyue Sung <isung@affinnova.com>, s-news@lists.biostat.wustl.edu
Subject: Re: setwd() analogue
From: "Richard M. Heiberger" <rmh@temple.edu>
Date: Thu, 23 Sep 2004 23:25:53 -0400
There are two distinct interpretations of your question.
Let me try both.


1. Change the .Data that is first on your search() list.
The .Data directory must already exist and you must have write permission.

attach("c:/HOME/tmp/.Data", pos=1)

Now all S-Plus objects that you create by assignment
    a <- 2:5
will be written in c:/HOME/tmp/.Data



2. Change the location where files other than S-Plus objects are
read and written.  In my usual setup,  I start S-Plus from
the c:/HOME/rmh directory and c:/HOME/rmh/.Data is in the first
position of my search() list.  A statement of the form
   myData <- read.table("myData.csv")
will find the file c:/HOME/rmh/myData.csv

I wish to read some data from another location, say from c:/datasets/

Define a function
   datasets <- function(filename) paste("c:/datasets", filename, sep="/")

Then access the file with
   myData <- read.table(datasets("myData.csv"))
This will read the file c:/datasets/myData.csv

The advantage of a function is that it can be changed external to the
read.table statement.  Indeed, it can define a different directory on
every computer you use and still work without changing any code.



My impression of your original question is that you were trying to
solve the second interpretation by a method appropriate to the first
interpretation.

Hui-May_Chu@vrtx.com gave a method similar to the second interpretation.

Tony Plate <tplate@blackmesacapital.com> was suggesting a startup
method equivalent to the first interpretation.

Rich

<Prev in Thread] Current Thread [Next in Thread>