Rikkoe@softhome.net
2002-Mar-25 20:26 UTC
[R] How do you organize the objects you produced?
Hello! It would be nice to hear how you organize the R-objects you produced. I found almost nothing about that neither in the R-manuals nor in two books about S. For example I am trying to find out, how to load the functions that I have written and that are now saved in a .txt-file in a Windows directory. Is copying and pasting it to the RGui console really the only feasible way to do that? Constructing packages, similar to the ones included in the basic R system, is probably too complicated for a beginner like me, isn?t it? I wonder why manuals and books just explain how to write functions, but not how to keep and to reload them. I have got a similar problem with my data. I understood (mistakenly?) that one can attach a Windows directory to the search path, so that every file inside this directory is known by R, without further need to specify the path. So I tried:> attach("C:\\Temp",2)Error in load(file, envir) : unable to open file> search()[1] ".GlobalEnv" "file:C:\\Temp" "package:ctest" "Autoloads" [5] "package:base" Temp is a directory and includes a file named test.dat. I went on:> file <- read.table("test.dat", header = TRUE, fill = TRUE)Error in file(file, "r") : cannot open file `test.dat' This last command only works when I use the RGui-menu to change my working directory to Temp. I feel I am using R as if cutting hair with a spoon. Do you know a nicer way to use it? Michael -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
"Rikkoe at softhome.net" wrote:> > Hello! > > It would be nice to hear how you organize the R-objects you produced. I > found almost nothing about that neither in the R-manuals nor in two books > about S. > > For example I am trying to find out, how to load the functions that I have > written and that are now saved in a .txt-file in a Windows directory. Is > copying and pasting it to the RGui console really the only feasible way to > do that? Constructing packages, similar to the ones included in the basic R > system, is probably too complicated for a beginner like me, isn?t it?Well, I wouldn't suggest to start learning R by creating your own packages. But after some experiences it's a nice thing. You are looking for source() It's mentioned in section 1.10 of "An Introduction to R" (this manual is really worth reading it completely; hint, hint!).> I wonder why manuals and books just explain how to write functions, but not > how to keep and to reload them. I have got a similar problem with my data. I > understood (mistakenly?) that one can attach a Windows directory to the > search path, so that every file inside this directory is known by R, without > further need to specify the path.Indeed, mistakenly.>From ?attach:"Usage: attach(what, pos = 2, name = deparse(substitute(what))) Arguments: what, ``database''. This may currently be a data.frame or list or a R data file created with save." You can set your working directory (see below).> So I tried: > > > attach("C:\\Temp",2) > Error in load(file, envir) : unable to open file > > search() > [1] ".GlobalEnv" "file:C:\\Temp" "package:ctest" "Autoloads" > [5] "package:base" > > > Temp is a directory and includes a file named test.dat. I went on:Well, as cited above: it's a directory, but neither a data.frame nor a list nor a R data file.> > file <- read.table("test.dat", header = TRUE, fill = TRUE) > Error in file(file, "r") : cannot open file `test.dat' > > This last command only works when I use the RGui-menu to change my working > directory to Temp. > > I feel I am using R as if cutting hair with a spoon. Do you know a nicer way > to use it?Instead of using the GUI, you can set your working directory with setwd("c:/temp") Additionally, read.table() [and any other function] also works for whole paths, e.g.: "c:/temp/test.dat". Uwe Ligges -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
ripley@stats.ox.ac.uk
2002-Mar-25 21:25 UTC
[R] How do you organize the objects you produced?
On Mon, 25 Mar 2002, Rikkoe at softhome.net wrote:> It would be nice to hear how you organize the R-objects you produced. I > found almost nothing about that neither in the R-manuals nor in two books > about S.They do explain about packages.> For example I am trying to find out, how to load the functions that I have > written and that are now saved in a .txt-file in a Windows directory. Is > copying and pasting it to the RGui console really the only feasible way to > do that? Constructing packages, similar to the ones included in the basic R > system, is probably too complicated for a beginner like me, isnĀ“t it?No.> I wonder why manuals and books just explain how to write functions, but not > how to keep and to reload them. I have got a similar problem with my data. IUm, a book called `S Programming' does. -- 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 272860 (secr) Oxford OX1 3TG, UK Fax: +44 1865 272595 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._