Hi,
?pairlist gives no explanation about what exactly is the difference
between a pairlist and a list (except that a pairlist of length 0
is 'NULL'). So, what's a pairlist?
class(.Options)
[1] "pairlist"
Some strange things about the "pairlist" type:
> showClass("pairlist")
Error in getClass(Class) : "pairlist" is not a defined class
Why the above doesn't work? It works for "list":
> showClass("list")
No Slots, prototype of class "list"
Extends: "vector"
> is.list(.Options)
[1] TRUE
> is.vector(.Options)
[1] FALSE
This doesn't make sense! If 'x' is a list, then it should be considered
a vector too.
Subsetting a pairlist with [] doesn't produce a pairlist:
> class(.Options[1:3])
[1] "list"
Yes, this one is documented, but still...
Cheers,
H.
pairlist objects
3 messages · Hervé Pagès, Hin-Tak Leung, Simon Urbanek
?list has a little bit of information. As far as I know, historically, the more inefficient one (pairlist()) came first, where R inherits its structure and implementation from LISP ; list() came later as a new implementation of a list-like object which is more efficient and faster in various manner (e.g. addressing the (n)th elements in the middle, and overall storage size). So these days most list-like stuff within R is done as list()'s rather than pairlist()'s. Internally, a pairlist() in R is implemented as a recursive binary tree (LISTSXP), where one branch of the first node consists of the first elements, its attributes, and the other branch consists of a daughter node which consists of the 2nd element as its one branch, etc. Walking such a tree is slow and its storage requirement is a bit larger than list(). Internally, a list() in R is a VECSXP, which is a one-dimensional structure, plus some attributes storing the names of the elements, etc. It is a bit more efficient in terms of storage (a 1-D structure vs a recursive binary tree), and also in random addressing of its elements - e.g. you can jump to the (n)th element without walking the 1st to the (n-1)th elements. This is my understanding, no doubt the R core team has more and better way to say about this. a list() is not of class vector (despite the implementation in C being a VECSXP) - a vector in R is a 1-D structure where all the elements are of the same type/mode, which a list() is not.
hpages at fhcrc.org wrote:
Hi, ?pairlist gives no explanation about what exactly is the difference between a pairlist and a list (except that a pairlist of length 0 is 'NULL'). So, what's a pairlist? class(.Options) [1] "pairlist" Some strange things about the "pairlist" type:
> showClass("pairlist")
Error in getClass(Class) : "pairlist" is not a defined class Why the above doesn't work? It works for "list":
> showClass("list")
No Slots, prototype of class "list" Extends: "vector"
> is.list(.Options)
[1] TRUE
> is.vector(.Options)
[1] FALSE This doesn't make sense! If 'x' is a list, then it should be considered a vector too. Subsetting a pairlist with [] doesn't produce a pairlist:
> class(.Options[1:3])
[1] "list" Yes, this one is documented, but still... Cheers, H.
______________________________________________ R-devel at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
On Oct 1, 2007, at 10:28 PM, hpages at fhcrc.org wrote:
?pairlist gives no explanation about what exactly is the difference between a pairlist and a list (except that a pairlist of length 0 is 'NULL'). So, what's a pairlist?
I read "traditional _dotted pair_ lists (as in LISP)" there - c.f. also http://cran.r-project.org/doc/manuals/R-lang.html#Pairlist-objects
class(.Options) [1] "pairlist" Some strange things about the "pairlist" type:
showClass("pairlist")
Error in getClass(Class) : "pairlist" is not a defined class Why the above doesn't work?
Because "pairlist" is not a formal class. Why should it?
It works for "list":
showClass("list")
No Slots, prototype of class "list" Extends: "vector"
is.list(.Options)
[1] TRUE
is.vector(.Options)
[1] FALSE This doesn't make sense! If 'x' is a list, then it should be considered a vector too.
Why? They are completely different objects. lists are generic vectors, pairlists are not vectors (c.f. the docs above).
Subsetting a pairlist with [] doesn't produce a pairlist:
class(.Options[1:3])
[1] "list" Yes, this one is documented, but still...
As the docs say, on R level pairlists are usually converted to vectors as the use of pairlists is deprecated. Cheers, Simon