Petr Pikal wrote:> Hallo > > On 9 Jun 2004 at 2:06, Utsav Boobna wrote: > > >>Hi, >> I am a newbie to R, just trying to switch from >>Splus. I am wondering to know if there is any such >>command in R as "attach" in Splus which can be used to >>attach the full directory. > > > I would recommend you to spent some time going through docummentation and > especially FAQs. > > getwd and setwd for setting the working directory > > but in R objects are stored in one file .Rdata.I prefer to control which objects are stored, and to use compression, by using save( ) and load( ), rather than using the .Rdata mechanism. save( ) can store one object or an entire series of objects in one .rda file. Frank> > OTOH in S+ objects are (were - I did not use it since quite a lot time) stored as > separate files. > > For attaching objects see > > ?attach > > Cheers > Petr > > >>Also, any idea/referrence about, how to load c >>functions in R would be highly appreciated. >> >>Thanks, >>Utsav >> >>______________________________________________ >>R-help at stat.math.ethz.ch mailing list >>https://www.stat.math.ethz.ch/mailman/listinfo/r-help >>PLEASE do read the posting guide! >>http://www.R-project.org/posting-guide.html > > > Petr Pikal > petr.pikal at precheza.cz > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://www.stat.math.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html >-- Frank E Harrell Jr Professor and Chair School of Medicine Department of Biostatistics Vanderbilt University
Hi, I am a newbie to R, just trying to switch from Splus. I am wondering to know if there is any such command in R as "attach" in Splus which can be used to attach the full directory. Also, any idea/referrence about, how to load c functions in R would be highly appreciated. Thanks, Utsav
Hallo On 9 Jun 2004 at 2:06, Utsav Boobna wrote:> Hi, > I am a newbie to R, just trying to switch from > Splus. I am wondering to know if there is any such > command in R as "attach" in Splus which can be used to > attach the full directory.I would recommend you to spent some time going through docummentation and especially FAQs. getwd and setwd for setting the working directory but in R objects are stored in one file .Rdata. OTOH in S+ objects are (were - I did not use it since quite a lot time) stored as separate files. For attaching objects see ?attach Cheers Petr> > Also, any idea/referrence about, how to load c > functions in R would be highly appreciated. > > Thanks, > Utsav > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://www.stat.math.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! > http://www.R-project.org/posting-guide.htmlPetr Pikal petr.pikal at precheza.cz
> From: Frank E Harrell Jr > > Petr Pikal wrote: > > Hallo > > > > On 9 Jun 2004 at 2:06, Utsav Boobna wrote: > > > > > >>Hi, > >> I am a newbie to R, just trying to switch from > >>Splus. I am wondering to know if there is any such > >>command in R as "attach" in Splus which can be used to > >>attach the full directory. > > > > > > I would recommend you to spent some time going through > docummentation and > > especially FAQs. > > > > getwd and setwd for setting the working directory > > > > but in R objects are stored in one file .Rdata. > > I prefer to control which objects are stored, and to use > compression, by > using save( ) and load( ), rather than using the .Rdata mechanism. > save( ) can store one object or an entire series of objects > in one .rda > file.I mostly do the same. For fairly large objects or objects that I do not want to accidentally alter during a session, I use attach() instead of load(). One convenience of attach() is that since the objects are not loaded into .GlobalEnv, I would have a less cluttered .RData even if I do save the workspace when I q(). Cheers, Andy> Frank > > > > > OTOH in S+ objects are (were - I did not use it since quite > a lot time) stored as > > separate files. > > > > For attaching objects see > > > > ?attach > > > > Cheers > > Petr > > > > > >>Also, any idea/referrence about, how to load c > >>functions in R would be highly appreciated. > >> > >>Thanks, > >>Utsav > >> > >>______________________________________________ > >>R-help at stat.math.ethz.ch mailing list > >>https://www.stat.math.ethz.ch/mailman/listinfo/r-help > >>PLEASE do read the posting guide! > >>http://www.R-project.org/posting-guide.html > > > > > > Petr Pikal > > petr.pikal at precheza.cz > > > > ______________________________________________ > > R-help at stat.math.ethz.ch mailing list > > https://www.stat.math.ethz.ch/mailman/listinfo/r-help > > PLEASE do read the posting guide! > http://www.R-project.org/posting-guide.html > > > > > -- > Frank E > Harrell Jr Professor and Chair School of Medicine > Department of Biostatistics > Vanderbilt University > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://www.stat.math.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! > http://www.R-project.org/posting-guide.html > >
Now that I acutally read the original question: If there are .RData files in other directories that you want to attach(), you can certainly do that. One difference between R and S-plus is that in S-plus you can attach() a directory at position 1, effectively making that the place that new objects are stored. In R, attach()ing at position 1 is not allowed. I must say that I like the way R works better, as it does a better job at preventing me from keeping garbage around. Best, Andy> From: Liaw, Andy > > > From: Frank E Harrell Jr > > > > Petr Pikal wrote: > > > Hallo > > > > > > On 9 Jun 2004 at 2:06, Utsav Boobna wrote: > > > > > > > > >>Hi, > > >> I am a newbie to R, just trying to switch from > > >>Splus. I am wondering to know if there is any such > > >>command in R as "attach" in Splus which can be used to > > >>attach the full directory. > > > > > > > > > I would recommend you to spent some time going through > > docummentation and > > > especially FAQs. > > > > > > getwd and setwd for setting the working directory > > > > > > but in R objects are stored in one file .Rdata. > > > > I prefer to control which objects are stored, and to use > > compression, by > > using save( ) and load( ), rather than using the .Rdata mechanism. > > save( ) can store one object or an entire series of objects > > in one .rda > > file. > > I mostly do the same. For fairly large objects or objects > that I do not > want to accidentally alter during a session, I use attach() instead of > load(). One convenience of attach() is that since the objects are not > loaded into .GlobalEnv, I would have a less cluttered .RData > even if I do > save the workspace when I q(). > > Cheers, > Andy > > > > Frank > > > > > > > > OTOH in S+ objects are (were - I did not use it since quite > > a lot time) stored as > > > separate files. > > > > > > For attaching objects see > > > > > > ?attach > > > > > > Cheers > > > Petr > > > > > > > > >>Also, any idea/referrence about, how to load c > > >>functions in R would be highly appreciated. > > >> > > >>Thanks, > > >>Utsav > > > > > > Petr Pikal > > > petr.pikal at precheza.cz > > > > > > ______________________________________________ > > > R-help at stat.math.ethz.ch mailing list > > > https://www.stat.math.ethz.ch/mailman/listinfo/r-help > > > PLEASE do read the posting guide! > > http://www.R-project.org/posting-guide.html > > > > > > > > > -- > > Frank E > > Harrell Jr Professor and Chair School of Medicine > > Department of Biostatistics > > Vanderbilt University
Hi Petr, I don't think I've said anything that is inconsistent with what you said, have I? The strategy that you mentioned is the one that is recommended, and I use it myself. However, life is not always that simple. There are times when the task at hand involves data/code/whatever that live in a different directory (perhaps most likely either the parent- or sub-directory of pwd). .RData is just a .rda file, and thus can be attach()ed, and that's what I said in my sentence. E.g., I can attach("subdirectory/.RData"), then use ls(2) to see what's in there. (ls() does have a few optional arguments.) Regarding save(), you can save to anywhere by using full path in the file name (otherwise it wouldn't be terribly useful). Best, Andy> From: Petr Pikal > > Hallo Andy, > > Well, my original respond was to Utsav's question if it is > possible to attach a > directory in R as in S+. > > I personally prefer to start R session from a directory where > I have all data and > results from certain project (txt, doc, xls, png, pdf....). > Therefore I use only > .RData and I usually store histories of my work in separate > files, so as basically all > my data and my knowledge of attaching different directories > in one session is not > at all comprehensive. > > But if I am not mistaken you cannot attach a directory > without some suitable file > (.RData or saved file) in it but you can specify different > working directory by > setwd() and list files in it by list.files(). I presume that > after setwd() I can > attach(".RData") to get access to objects from it but ls() > still gives me list of > objects stored in an .RData file in the directory from which > R was started. > > OTOH saving an object by save(object, file="myfile") saves > the object to > directory specified by setwd(). > > Cheers > Petr > > On 9 Jun 2004 at 9:00, Liaw, Andy wrote: > > > Now that I acutally read the original question: > > > > If there are .RData files in other directories that you want to > > attach(), you can certainly do that. One difference between R and > > S-plus is that in S-plus you can attach() a directory at position 1, > > effectively making that the place that new objects are > stored. In R, > > attach()ing at position 1 is not allowed. I must say that > I like the > > way R works better, as it does a better job at preventing me from > > keeping garbage around. > > > > Best, > > Andy > > > > > From: Liaw, Andy > > > > > > > From: Frank E Harrell Jr > > > > > > > > Petr Pikal wrote: > > > > > Hallo > > > > > > > > > > On 9 Jun 2004 at 2:06, Utsav Boobna wrote: > > > > > > > > > > > > > > >>Hi, > > > > >> I am a newbie to R, just trying to switch from > > > > >>Splus. I am wondering to know if there is any such > > > > >>command in R as "attach" in Splus which can be used to > > > > >>attach the full directory. > > > > > > > > > > > > > > > I would recommend you to spent some time going through > > > > docummentation and > > > > > especially FAQs. > > > > > > > > > > getwd and setwd for setting the working directory > > > > > > > > > > but in R objects are stored in one file .Rdata. > > > > > > > > I prefer to control which objects are stored, and to use > > > > compression, by > > > > using save( ) and load( ), rather than using the .Rdata > mechanism. > > > > save( ) can store one object or an entire series of > objects in one > > > > .rda file. > > > > > > I mostly do the same. For fairly large objects or objects > > > that I do not > > > want to accidentally alter during a session, I use > attach() instead > > > of load(). One convenience of attach() is that since the objects > > > are not loaded into .GlobalEnv, I would have a less > cluttered .RData > > > even if I do save the workspace when I q(). > > > > > > Cheers, > > > Andy > > > > > > > > > > Frank > > > > > > > > > > > > > > OTOH in S+ objects are (were - I did not use it since quite > > > > a lot time) stored as > > > > > separate files. > > > > > > > > > > For attaching objects see > > > > > > > > > > ?attach > > > > > > > > > > Cheers > > > > > Petr > > > > > > > > > > > > > > >>Also, any idea/referrence about, how to load c > > > > >>functions in R would be highly appreciated. > > > > >> > > > > >>Thanks, > > > > >>Utsav > > > > > > > > > > Petr Pikal > > > > > petr.pikal at precheza.cz > > > > > > > > > > ______________________________________________ > > > > > R-help at stat.math.ethz.ch mailing list > > > > > https://www.stat.math.ethz.ch/mailman/listinfo/r-help > > > > > PLEASE do read the posting guide! > > > > http://www.R-project.org/posting-guide.html > > > > > > > > > > > > > > > > > -- > > > > Frank E > > > > Harrell Jr Professor and Chair School of Medicine > > > > Department of Biostatistics > > > > Vanderbilt University > > > > ______________________________________________ > > R-help at stat.math.ethz.ch mailing list > > https://www.stat.math.ethz.ch/mailman/listinfo/r-help > > PLEASE do read the posting guide! > > http://www.R-project.org/posting-guide.html > > Petr Pikal > petr.pikal at precheza.cz > > > >