Re: [R] Storing user-defined R functions

From: David Scott <d.scott_at_auckland.ac.nz>
Date: Fri, 25 Mar 2011 10:46:56 +1300

  On 25/03/11 09:08, 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.
>
> -thomas
>
Another work around would involve defining a little function in your .Rprofile, as follows.

Choose a location for your code. The function would take the name of the file, prepend the path to the directory where your code is located and then call source. Two or three lines would do it.

Also, who knows, maybe Gabor has something clever in his batch files, he usually seems to.

David Scott

-- 
_________________________________________________________________
David Scott	Department of Statistics
		The University of Auckland, PB 92019
		Auckland 1142,    NEW ZEALAND
Phone: +64 9 923 5055, or +64 9 373 7599 ext 85055
Email:	d.scott_at_auckland.ac.nz,  Fax: +64 9 373 7018

Director of Consulting, Department of Statistics

______________________________________________
R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Received on Thu 24 Mar 2011 - 21:51:08 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 24 Mar 2011 - 22:10:25 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive