Skip to content

organizing work; dump function

3 messages · RINNER Heinrich, Friedrich Leisch, Thomas Lumley

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

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
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?

Heinrich Rinner.
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
#
RH> In the past I have used several different working directories for different
RH> projects, and during many of these projects I have written some functions
RH> for particular purposes. Now I thought I would be nice to have all these
RH> "personal" functions collected in one place, and to make them available in R
RH> no matter which working directory I use.

RH> Reading the manual "An Introduction to R Version 1.0.0", chapter 10.8
RH> ("Customizing the environment"), I guess the (best ?) way to this is to dump
RH> all my functions into one big file "myfunctions.R" and source that into R
RH> via a .First function in my Rprofile file.

RH> But, when I write new functions and want to add these to my personal
RH> collection "myfunctions.R", it would be nice to have something like
RH> AFAIK this isn't possible (there is no append argument to dump), so I guess
RH> I have to create new files each time and then copy these together somehow.

RH> So my questions are:
RH> 1) Does this way to organize ones functions make sense, or are there better
RH> alternatives?

I personally have a private package of functions, which has the
advantage that the various workspaces are not polluted by copies of
the functions (if you source() code, it gets into the global
environment, packages maintain their own environment).

RH> 2) If it makes sense, wouldn't an "append" argument to "dump" be a useful
RH> thing?

Yes, independent of the above usage.  I'll add the feature in the
devel version.

Best,
#
On Thu, 28 Sep 2000, RINNER Heinrich wrote:

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