[R] Storing and managing custom R functions for re-use

Bert Gunter gunter.berton at gene.com
Tue Jul 12 23:59:07 CEST 2011


These sorts of tasks can be automated. See:

?Startup

-- Bert

On Tue, Jul 12, 2011 at 2:48 PM, Steve Taylor <steve.taylor at aut.ac.nz> wrote:
> My solution to the clutter problem is this: at start-up time, create a list of functions, attach the list and then delete the list.  I haven't delved into making packages yet.
>
> if (any(search()=="MyFunctions")) detach(MyFunctions)
> MyFunctions <- list()
> MyFunctions$
>  "%like%" <- function(x,y) { seq_along(x) %in% grep(y,x,ignore=TRUE) }
> MyFunctions$
>  trim <- function(txt) { gsub("^ +| +$", "", txt) }
> # You can also put data into the list:
> MyFunctions$
>  tau = 2 * pi
> # etc...
> attach(MyFunctions)
> rm(MyFunctions)
>
> All that is in MyFunctions.R which I can source() again when I update it.
>
>>>>
>
> From: "Abhijit Dasgupta, PhD" <aikidasgupta at gmail.com>
> To:<s.chamaille at yahoo.fr>
> CC:<r-help at r-project.org>
> Date: 10/Jul/2011 1:40a
> Subject: Re: [R] Storing and managing custom R functions for re-use
> I think most of us are in a similar situation. I've usually kept mine in
> a file which is sourced when I start R. The main problem I have with
> this is that it clutters up my environment with a lot of stuff I don't
> need all the time. I'm in the process of creating a custom package which
> will be lazy-loaded. I believe a previous discussion of this topic
> suggested this as the preferred method.
>
>
>
>        [[alternative HTML version deleted]]
>
> ______________________________________________
> 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.
>



-- 
"Men by nature long to get on to the ultimate truths, and will often
be impatient with elementary studies or fight shy of them. If it were
possible to reach the ultimate truths without the elementary studies
usually prefixed to them, these would not be preparatory studies but
superfluous diversions."

-- Maimonides (1135-1204)

Bert Gunter
Genentech Nonclinical Biostatistics



More information about the R-help mailing list