Re: [Rd] Possible bug in 'relist()' and/or 'as.relistable()'

From: Simon Urbanek <simon.urbanek_at_r-project.org>
Date: Thu, 14 Apr 2011 17:45:45 -0400

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

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

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
>
>


R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Thu 14 Apr 2011 - 21:56:11 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 Fri 15 Apr 2011 - 07:20:49 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.

list of date sections of archive