Re: [Rd] [R] learning R

From: <markleeds_at_verizon.net>
Date: Wed, 25 Feb 2009 03:39:27 -0600 (CST)


  Hi Wacek: Somewhere I remember reading that environments have functionality like lists EXCEPT for the names part. IIRC, I think that I read this in the R Language Reference manual also.

On Wed, Feb 25, 2009 at 4:32 AM, Wacek Kusnierczyk wrote:

> a quick follow-up:
>
> e = new.env()
> e$a = 1
> names(e)
> # NULL
> names(e) = 'a'
> # error in names(e) = "foo" : names() applied to a non-vector
>
> this is surprising. names(e) 'works', there is no complaint, but when
> names<- is used, the error is about the use of names, not names<-.
>
> btw. ?names says:
>
> "Description:
>
> Functions to get or set the names of an object.
>
> Usage:
>
> names(x)
> names(x) <- value
>
> Arguments:
>
> x: an R object.
> "
>
> and there is no clarification in the rest of the page that x cannot be
> an environment, or that it has to be a vector. furthermore:
>
> p = pairlist(a=1)
> names(p)
> # "a"
> names(p) = 'b'
> # fine
> is.vector(p)
> # FALSE
>
> which is incoherent with the above error message, in that p is *not* a
> vector.
>
> vQ
>
>
>
> Wacek Kusnierczyk wrote:
>>
>> the following:
>>
>> names(a[2]) = 'foo'
>>
>> has (partially) a functional flavour, in that you assign to the names
>> of
>> a *copy* of a part of a, while
>>
>> names(a)[2] = 'foo'
>>
>> does not have the flavour, in that you assign to the names of a; it
>> seems, according to the man page you quote, to be equivalent to:
>>
>> a = 'names<-'(a, '[<-.'(names(a), 2, 'foo'))
>>
>> which proceeds as follows:
>>
>> tmp1 = names(a)
>> # get a copy of the names of a, no effect on a
>>
>> tmp2 = '[<-'(tmp1, 2, 'foo')
>> # get a copy of tmp1 with the second element replaced with 'foo'
>> # no effect on either a or tmp1
>>
>> tmp3 = 'names<-'(a, tmp2)
>> # get a copy of a with its names replaced with tmp2
>> # no effect on either a, tmp1, or tmp2
>>
>> a = tmp3
>> # backassign the result to a
>>
>
> ______________________________________________
> R-help_at_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-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Wed 25 Feb 2009 - 08:48:19 GMT

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 26 Feb 2009 - 08:30:46 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