[R] organizing work; dump function

Thomas Lumley thomas at biostat.washington.edu
Thu Sep 28 17:06:27 CEST 2000


On Thu, 28 Sep 2000, RINNER Heinrich wrote:

> > Dear R-users!
> > 
> > I am using R 1.0.0 and Windows NT 4.0
> > 
> In the past I have used several different working directories for different
> projects, and during many of these projects I have written some functions
> for particular purposes. Now I thought I would be nice to have all these
> "personal" functions collected in one place, and to make them available in R
> no matter which working directory I use.
> 
> Reading the manual "An Introduction to R Version 1.0.0", chapter 10.8
> ("Customizing the environment"), I guess the (best ?) way to this is to dump
> all my functions into one big file "myfunctions.R" and source that into R
> via a .First function in my Rprofile file.

Another, slightly more efficient, way is to save() them into a file
"myfunctions.rda" and attach() that file. It doesn't help with your next
point, though
 
> But, when I write new functions and want to add these to my personal
> collection "myfunctions.R", it would be nice to have something like
> > dump("new.function", file="myfunctions.R", append=TRUE).
> AFAIK this isn't possible (there is no append argument to dump), so I guess
> I have to create new files each time and then copy these together somehow.
> 
> So my questions are:
> 1) Does this way to organize ones functions make sense, or are there better
> alternatives?
> 2) If it makes sense, wouldn't an "append" argument to "dump" be a useful
> thing?

It's fairly easy to join files together with cat under Unix or copy under
Windows. 

Another possibility  is to put the separate files in a directory called,
say, /path/to/myfunctions/ and do
  lapply(list.files("/path/to/myfunctions"),source)
which would read in all the files in that directory.

Yet another option is to create a package of files. In that case you would
dump() the new file to the package source directory and then re-run R
INSTALL to add it to the package.

So you would have a directory myfunctions/, with a DESCRIPTION file, and a
subdirectory  myfunctions/R/ that would store all the individual function
files.

Running 
	R INSTALL myfunctions 
would install the package and you could put
	library(myfunctions)
in your .First file.


	-thomas

Thomas Lumley
Assistant Professor, Biostatistics
University of Washington, Seattle

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list