Re: [Rd] Why is there no within.environment function?

From: peter dalgaard <pdalgd_at_gmail.com>
Date: Wed, 21 Mar 2012 23:23:11 +0100

On Mar 21, 2012, at 23:01 , William Dunlap wrote:

> 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.
> 

evalq() would be rather more to the point. Then again, with() _is_ really just a sugar-coated evalq().

within() was quite specifically created because you couldn't do the same kind of things with data frames that you could do with environments, so the current thread does seem a bit peculiar to me... (The original design of within() would modify the object in-place, like fix(), but Luke objected.)   

> 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
> ______________________________________________
> R-devel_at_r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
-- 
Peter Dalgaard, Professor,
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Email: pd.mes_at_cbs.dk  Priv: PDalgd_at_gmail.com

______________________________________________
R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Received on Wed 21 Mar 2012 - 22:39:51 GMT

This quarter's messages: by month, or sorted: [ by date ] [ by thread ] [ by subject ] [ by author ]

All messages

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 22 Mar 2012 - 01:40:32 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.

list of date sections of archive