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

______________________________________________
R-help@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.

Reply via email to