Skip to content

Possible bug in 'relist()' and/or 'as.relistable()'

2 messages · Janko Thyson, Simon Urbanek

#
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))))
a <- unlist(a)
relist(a)

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
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
#
On Apr 14, 2011, at 5:13 PM, Janko Thyson wrote:

            
Technically, you're not nesting pairlists - you' are putting a generic vector in a parilist ... (not that it matters here).
relist() has no method for pairlists - but you can actually use the "list" method as-is:
Dotted pair list of 3
 $ a: num 1
 $ b: num 2
 $ c:List of 2
  ..$ c.1: num 1
  ..$ c.2: num 2
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:
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
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