Hello,

list2env generates an error on empty lists.

> l <- list()
> list2env( l )
Erreur dans list2env(l) : names(x) must be valid character(length(x)).


This is consistent with the requirement that the list must be a __named__ list, so this works:

> names(l) <- character(0)
> list2env( l )
<environment: 0x102b8fbc8>


But I was wondering if it would make sense to make a special case of zero sized lists, with this:

Index: src/main/envir.c
===================================================================
--- src/main/envir.c    (revision 52910)
+++ src/main/envir.c    (working copy)
@@ -1555,7 +1555,7 @@
     x = CAR(args); args = CDR(args);
     n = LENGTH(x);
     xnms = getAttrib(x, R_NamesSymbol);
-    if (TYPEOF(xnms) != STRSXP || LENGTH(xnms) != n)
+    if (n && (TYPEOF(xnms) != STRSXP || LENGTH(xnms) != n) )
        error(_("names(x) must be valid character(length(x))."));
     envir = CAR(args);  args = CDR(args);
     if (TYPEOF(envir) == NILSXP) {


Romain

--
Romain Francois
Professional R Enthusiast
+33(0) 6 28 91 30 30
http://romainfrancois.blog.free.fr
|- http://bit.ly/cCmbgg : Rcpp 0.8.6
|- http://bit.ly/bzoWrs : Rcpp svn revision 2000
`- http://bit.ly/b8VNE2 : Rcpp at LondonR, oct 5th

______________________________________________
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel

Reply via email to