[R] Storing user-defined R functions

Duncan Murdoch murdoch.duncan at gmail.com
Fri Mar 25 00:07:03 CET 2011


On 11-03-24 4:08 PM, Thomas Lumley wrote:
> 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.

  ... and you don't get the standard layout and naming conventions so 
you have to invent your own, and nobody will want to share your code, 
and it will be much more difficult to integrate C or C++ or Fortran 
code.  David *really* should use packages.

Duncan Murdoch



More information about the R-help mailing list