Possible bug in 'relist()' and/or 'as.relistable()'
On Apr 14, 2011, at 5:13 PM, Janko Thyson wrote:
Dear list, I think I just stumbled across a bug in either 'relist()' and/or 'as.relistable()'. It seems that 'pairlists' can only be un- and relisted as long as they're not nested: Good: a <- as.relistable(as.pairlist(list(a=1, b=2))) a <- unlist(a) relist(a)# Works Bad: a <- as.relistable(as.pairlist(list(a=1, b=2, c=list(c.1=1, c.2=2))))
Technically, you're not nesting pairlists - you' are putting a generic vector in a parilist ... (not that it matters here).
a <- unlist(a) relist(a)
relist() has no method for pairlists - but you can actually use the "list" method as-is:
relist.pairlist <- utils:::relist.list str(src <- as.pairlist(list(a=1, b=2, c=list(c.1=1, c.2=2))))
Dotted pair list of 3 $ a: num 1 $ b: num 2 $ c:List of 2 ..$ c.1: num 1 ..$ c.2: num 2
str(relist(unlist(as.relistable(src))))
Dotted pair list of 3 $ a: num 1 $ b: num 2 $ c:List of 2 ..$ c.1: num 1 ..$ c.2: num 2 - attr(*, "class")= chr [1:2] "relistable" "pairlist" and that will also support actual nested pairlists:
str(src <- pairlist(a=1, b=2, c=pairlist(c.1=1, c.2=2)))
Dotted pair list of 3 $ a: num 1 $ b: num 2 $ c:Dotted pair list of 2 ..$ c.1: num 1 ..$ c.2: num 2
str(relist(unlist(as.relistable(src))))
Dotted pair list of 3 $ a: num 1 $ b: num 2 $ c:Dotted pair list of 2 ..$ c.1: num 1 ..$ c.2: num 2 - attr(*, "class")= chr [1:2] "relistable" "pairlist" so I guess it should be easy to add relist.pairlist to utils ... I'm not sure about the implications, but it does sound appealing. Cheers, Simon
The help page didn't say anything about pairlists and I don't know if they're at all relevant, but I'm using them whenever I want my functions to recognize a clear 'name-value' structure (e.g. for batch assigning variables) as opposed to standard list structures. Cheers, Janko
sessionInfo()
R version 2.12.1 (2010-12-16) Platform: i386-pc-mingw32/i386 (32-bit) locale: [1] LC_COLLATE=German_Germany.1252 LC_CTYPE=German_Germany.1252 [3] LC_MONETARY=German_Germany.1252 LC_NUMERIC=C [5] LC_TIME=German_Germany.1252 attached base packages: [1] stats graphics grDevices utils datasets methods base loaded via a namespace (and not attached): [1] codetools_0.2-8 tools_2.12.1
______________________________________________ R-devel at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel