Skip to content

list2env( list() )

1 message · Romain Francois

#
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