On 8/1/2008 9:46 AM, Benjamin Otto wrote:
Hi,
I would like to convert a simple list into an environment object. It seems I
have to create an environment object with new.env() and assign the single
values afterwards. Now what I did not really understand from the guides
until now is, how the parent environment supplied to the new.env() function
influence the final environment. So:
Environments aren't just lists of objects, they also specify where to
look if a particular entry is not found, i.e. they say to look in the
parent.
1. Do I ALWAYS have to supply a parent during creation?
No, you'll get a default one, which is the current evaluation
environment. For example,
> f <- function() {
+ x <- 123
+ return(new.env())
+ }
>
> e <- f()
> e$x
NULL
Using the $ notation does *not* look in the parent.
> get("x", e)
[1] 123
Using get() does, unless
> get("x", e, inherits=FALSE)
Error in get("x", e, inherits = FALSE) : variable "x" was not found
you say "inherits=FALSE".
Duncan Murdoch
2. If yes, what would that be, when all I want is a conversion from a simple
list?
Best regards
Benjamin
======================================
Benjamin Otto
University Hospital Hamburg-Eppendorf
Institute For Clinical Chemistry
Martinistr. 52
D-20246 Hamburg
Tel.: +49 40 42803 1908
Fax.: +49 40 42803 4971
======================================
------------------------------------------------------------------------
______________________________________________
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.
______________________________________________
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.