[R] Saving a function

Michael Prager mike.prager at noaa.gov
Thu Nov 2 02:22:48 CET 2006


patopatasfrias wrote:

> Hey, I'm a real novice...  how do I go about saving a function that I created 
> eg. If I created this function: Fun<-function(x1,X2) {......}, how can I
> store it so that the next time I use R I can load it and not have to type it
> out again????

If you search the list archives, you may find a solution to
this that I posted several months ago.  It involves moving
one's own functions to a dedicated directory, saving them in
an R workspace in that directory, and then loading that
workspace in the .Rprofile file.  

My method is a LOT simpler than making an R package but it is
more complex than saving the functions with dput or otherwise
in a file to be reloaded.  Its advantage is that (like making
a package) it makes the functions available to you even when
you open R in a different directory.


Mike Prager
Southeast Fisheries Science Center, NOAA
Beaufort, North Carolina  USA

More information about the R-help mailing list