Re: [Rd] [R] learning R

From: Wacek Kusnierczyk <>
Date: Wed, 25 Feb 2009 10:32:03 +0100

a quick follow-up:

    e = new.env()
    e$a = 1
    # 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:


     Functions to get or set the names of an object.


     names(x) <- value


       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)
    # "a"
    names(p) = 'b'
    # fine
    # FALSE which is incoherent with the above error message, in that p is *not* a vector.


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
> mailing list Received on Wed 25 Feb 2009 - 08:37:58 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 Wed 25 Feb 2009 - 10:30:43 GMT.

Mailing list information is available at Please read the posting guide before posting to the list.

list of date sections of archive