[Rd] Assignment in environment

Daniel Kaschek daniel.kaschek at physik.uni-freiburg.de
Sun Feb 7 14:08:09 CET 2016


Dear all,

I have a function "fn" with its own environment, i.e.

env <- environment(fn)

and env is not .GlobalEnv. And another function

getValue <- function(x) environment(x)$mylist

which returns the list object "mylist" which is in "env". If I want to 
modify "mylist", I could write

'getValue<-' <- function(x, value) { environment(x)$mylist <- value}

which gives not the desired result, e.g.

getValue(fn)[[1]] <- 3

will set the first list entry of "mylist" to 3. But then "fn" will also 
be 3!

environment(fn)$mylist[[1]] <- 3

does set the list entry correctly while keeping "fn". What's the 
difference?

Cheers,
Daniel



More information about the R-devel mailing list