[Rd] unlist on nested pairlists

From: Dan Davison <davison_at_stats.ox.ac.uk>
Date: Wed, 20 Aug 2008 17:19:13 +0100

unlist(recursive=FALSE) returns NULL elements when passed a nested pairlist containing non-NULL data:

x <- pairlist(pairlist(1:2))
unlist(x, recursive=FALSE)
## [[1]]
## NULL
version 2.7.2 RC (2008-08-18 r46382) under linux

I'm unaware of any motivation for constructing the above data structure, but if unlist is going to operate on it without error I would be surprised if that is the correct answer. However as I do not know anything about pairlists I have not submitted this to r-bugs.

I'd also appreciate any comments on the following issue:

The documentation for unlist says

recursive: logical. Should unlisting be applied to list components of

'x'?

Now,

y <- list(a=1:2, b=list(b1=3:4, b2=5:6))

My expectation was that unlist(y, recursive=FALSE) would be the following length 3 list: list(a1=1, a2=2, b=list(b1=3:4, b2=5:6))

However

str(unlist(y, recursive=FALSE))
## List of 4
## \$ a1 : int 1
## \$ a2 : int 2
## \$ b.b1: int [1:2] 3 4
## \$ b.b2: int [1:2] 5 6

I'm tempted to say that, contary to the documentation, (partial) unlisting has in fact been applied to a list component of x (x\$b): it contributes 2 components to the result, rather than one. I say partial because the numeric vectors in x\$b have not been broken up into separate elements in the answer. However, I imagine that this is the intended behaviour, and that my incorrect expectation is a result of not understanding the underlying list representations. Any explanation would be appreciated.

Dan

--
http://www.stats.ox.ac.uk/~davison

______________________________________________
R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Received on Wed 20 Aug 2008 - 16:22:13 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 20 Aug 2008 - 20:38:22 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.