Michael Friendly
2010-Jul-22 12:58 UTC
[R] namespace? environment? how to manage functions?
In http://tolstoy.newcastle.edu.au/R/e7/help/09/06/1900.html Jim Holtman wrote: Here is the way that I do it instead of creating a package of my functions. I 'source' the file into an environment and then attach the environment to keep the global from being clustered: # read my functions into a environment .my.env <- new.env() sys.source('c:/perf/bin/perfmon.r', envir=.my.env) attach(.my.env) Is there a way to do this directly in .Rprofile without sourcing from a separate file? I've looked at sys.source, but don't understand how it works. -- 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 Web: http://www.datavis.ca Toronto, ONT M3J 1P3 CANADA
On 22/07/2010 8:58 AM, Michael Friendly wrote:> In http://tolstoy.newcastle.edu.au/R/e7/help/09/06/1900.html > Jim Holtman wrote: > > Here is the way that I do it instead of creating a package of my > functions. I 'source' the file into an environment and then attach the > environment to keep the global from being clustered: > > # read my functions into a environment > .my.env <- new.env() > sys.source('c:/perf/bin/perfmon.r', envir=.my.env) attach(.my.env) > > Is there a way to do this directly in .Rprofile without sourcing from a > separate file? I've looked at > sys.source, but don't understand how it works. > >You mean you want all your definitions in the Rprofile file? The way to do that is to use local(). That is, .my.env <- local({ f <- function(x) x^2 # all your other definitions environment() # Put this as the last line, to return the environment that local() created, where # all your definitions now live }) attach(.my.env) Duncan Murdoch
Seemingly Similar Threads
- locked binding of setwd() in R 2.15.x causes .Rprofile to fail
- Rprofile: distinguish between Rgui, Rterm, JGR?
- Installing/updating packages on a lab network
- Installing/updating packages on a lab network
- assignInNamespace to create a setwd() replacement: how to use unlockBinding()?