Michael Friendly
2010-Feb-01 18:19 UTC
[R] hiding/protecting utility functions in .Rprofile
[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 Dept. 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
Instead of putting the functions into .Rprofile, save them as a package or use save to put them in a .Rdata file. Then in .Rprofile you can load the package or attach the .Rdata file. Hope this helps, -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare greg.snow at imail.org 801.408.8111> -----Original Message----- > From: r-help-bounces at r-project.org [mailto:r-help-bounces at r- > project.org] On Behalf Of Michael Friendly > Sent: Monday, February 01, 2010 11:19 AM > To: R-Help > Subject: [R] hiding/protecting utility functions in .Rprofile > > [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 Dept. > 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 > 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.
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 > Dept. > 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 > 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. >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.