[Rd] unlisting a list with names components (PR#645)
ripley@stats.ox.ac.uk
ripley@stats.ox.ac.uk
Fri, 29 Dec 2000 10:44:09 +0100 (MET)
Summary of report from Peter Perkins <pperkins@ucsd.edu> on Sat Aug 26
09:41:52 2000
i think the lines below demonstrate a problem with unlist when the list
contains components that are names. _anything_ can go in a list,
right? this came up in the context of trying to
unlist(list(attr(terms(formula), "variables")).
> list2 <- list(a="a", b=as.name("b"))
> unlist(list2)
$a
[1] "a"
$b
b
This seems to be intentional, but the documentation is wrong. The C code
says
/* If a non-vector argument was encountered (perhaps a list if */
/* recursive = F) then we must return a list. Otherwise, we use */
/* the natural coercion for vector types. */
A language element (e.g. a `name') is non-vector. So anything can go in a
list, but unlist cannot sort out anything.
S does this differently, but then it stores non-vector types differently.
--
Brian D. Ripley, ripley@stats.ox.ac.uk
Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel: +44 1865 272861 (self)
1 South Parks Road, +44 1865 272860 (secr)
Oxford OX1 3TG, UK Fax: +44 1865 272595
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-devel-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._