[R] Storing user-defined R functions

Thomas Lumley tlumley at uw.edu
Thu Mar 24 21:08:15 CET 2011


On Fri, Mar 25, 2011 at 5:11 AM, David.Epstein
<David.Epstein at warwick.ac.uk> wrote:
> Hello, I don't want to find out how to make packages unless that becomes
> necessary. Also, I don't want to clog up the computer memory with functions
> that I'm not using. (It would be great if someone in this forum would
> explain how memory is used when I type library(MASS) and then use only one
> function from MASS. Are all the many MASS functions then residing in memory,
> or only the one I called?)

There is a lazy-loading system that loads functions and datasets only
on demand.  Not all packages use it, but MASS does.

> Is there some standard way of
> 1. storing the R functions that I define, each in a separate file in some
> standard directory, and then
> 2. calling one of these functions without having to include the path to the
> relevant directory?
> 3. If so, are there conventional places to keep such files, akin to
> /usr/local/bin in Unix?

No.

You really do want to learn to make packages.  It isn't that hard.

However, another possibility is to use save() to save a file
containing all your functions and then use attach() to make these
functions available.  This works like making a package except that you
don't get lazy-loading, you don't get documentation, and you don't get
the package checks.

   -thomas

-- 
Thomas Lumley
Professor of Biostatistics
University of Auckland



More information about the R-help mailing list