From ggrothendieck at gmail.com  Wed Mar 21 23:00:53 2012
From: ggrothendieck at gmail.com (Gabor Grothendieck)
Date: Wed, 21 Mar 2012 18:00:53 -0400
Subject: [Rd] Why is there no within.environment function?
In-Reply-To: <CAPp_+=dLEZzw+ENwTkNmWz-cKZXpQ67NwwUje6EqxWLwMuBufA@mail.gmail.com>
References: <CAPp_+=dLEZzw+ENwTkNmWz-cKZXpQ67NwwUje6EqxWLwMuBufA@mail.gmail.com>
Message-ID: <CAP01uRkYxfKtcJzbk5S3mNTNW3ugh8WDaLLF9x8N1yNzs-3tTQ@mail.gmail.com>

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



[Rd] Why is there no within.environment function?
Gabor Grothendieck