Skip to content
Prev 171629 / 398503 Next

learning R

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: