[R] hiding/protecting utility functions in .Rprofile
clc559 at gmail.com
Tue Feb 2 16:56:12 CET 2010
On Mon, Feb 1, 2010 at 13:19, Michael Friendly <friendly at yorku.ca> wrote:
> [Env: WinXp, R 2.9.2]
> In my .Rprofile, I define a number of utility functions I'd like to have
> available in my R session, but don't want them
> to be *normally* listed by ls(), or more importantly, saved if I save my
> session variables/functions.
> How can I do this?
> Michael Friendly Email: friendly AT yorku DOT ca Professor, Psychology
> York University Voice: 416 736-5115 x66249 Fax: 416 736-5814
> 4700 Keele Street http://www.math.yorku.ca/SCS/friendly.html
> Toronto, ONT M3J 1P3 CANADA
> R-help at r-project.org mailing list
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
My strategy for loading my own functions at startup is to keep my
functions in a separate file (not .Rprofile) that I source into its
own environment via .Rprofile.
My .Rprofile looks like this:
.diag <- new.env()
sys.source( "/path/to/sourcefile/functions_to_load.R", envir = .diag )
attach( .diag )
I can't claim credit for this; I put it together from other posts on
this mailing list, but I don't remember the source now. And I cannot
speak to whether this is the "best" way, but it works fine for me.
Hope that helps.
More information about the R-help