If I want to assign some variables into an environment, it seems natural to do something like e <- new.env() within(e, { x <- 1:5 y <- runif(5) } ) This throws an error, since within.environment doesn't exist.? I realise I can work around it using as.environment(within(as.list(e), { x <- 1:5 y <- runif(5) } )) Just wondering why I can't use within directly with environments. -- 4dpiecharts.com
Gabor Grothendieck
2012-Mar-21 22:00 UTC
[Rd] Why is there no within.environment function?
On Wed, Mar 21, 2012 at 5:51 PM, Richard Cotton <richierocks at gmail.com> wrote:> If I want to assign some variables into an environment, it seems > natural to do something like > > e <- new.env() > within(e, > ? ?{ > ? ? ?x <- 1:5 > ? ? ?y <- runif(5) > ? ?} > ) > > This throws an error, since within.environment doesn't exist.? I > realise I can work around it using >'with' already does that: e <- new.env() with(e, { x <- 1.5 y <- runif(5) }) ls(e) # lists x and y Also since proto objects are environments this works: library(proto) p <- proto(x = 1.5, y = runif(5)) p$ls() # lists x and y -- Statistics & Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.com
Wouldn't within.environment be identical to with.environment? > e <- new.env() > with(e, { One <- 1 ; Two <- 2+2i ; Theee <- One + Two }) > objects(e) [1] "One" "Theee" "Two" It might make the transition between lists and environments simpler if within.environment existed. Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com> -----Original Message----- > From: r-devel-bounces at r-project.org [mailto:r-devel-bounces at r-project.org] On Behalf > Of Richard Cotton > Sent: Wednesday, March 21, 2012 2:51 PM > To: r-devel at r-project.org > Subject: [Rd] Why is there no within.environment function? > > If I want to assign some variables into an environment, it seems > natural to do something like > > e <- new.env() > within(e, > { > x <- 1:5 > y <- runif(5) > } > ) > > This throws an error, since within.environment doesn't exist.? I > realise I can work around it using > > as.environment(within(as.list(e), > { > x <- 1:5 > y <- runif(5) > } > )) > > Just wondering why I can't use within directly with environments. > > -- > 4dpiecharts.com > > ______________________________________________ > R-devel at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-devel
Reasonably Related Threads
- \U with more than 4 digits returns the wrong character
- Unicode display problem with data frames under Windows
- PDFs and SVGs containing rasterGrobs don't display correctly in some other software
- capturing warnings using capture.output
- Unicode display problem with data frames under Windows