Skip to content
Prev 35952 / 63424 Next

Rubbish values written with zero-length vectors (PR#14217)

seth at userprimary.net wrote:
Thanks, Seth. Martin Morgan sent a patch for a few lines above yours, 
which I didn't have a chance to review until now:

-   if (!isVectorList(x) && LENGTH(y) > 1)
-       error(_("more elements supplied than there are to replace"));
+   if (!isVectorList(x) && LENGTH(y) != 1)
+       if (LENGTH(y) == 0)
+           error(_("fewer elements supplied than there are to replace"));
+       else
+           error(_("more elements supplied than there are to replace"));

I _think_ that you are both right that there is no way for a zero-length 
RHS not to be an error. E.g.,

 > x[[0]] <- real(0)
Error in x[[0]] <- real(0) : attempt to select less than one element

The difference between Seth's solution and Martin's is whether to 
pre-check for nsubs==1, and I don't think we want that because of

 > x <- matrix(1:4,2,2)
 > x[[2,2]]
[1] 4
 > x[[2,2]] <- integer(0)
 > x
      [,1]      [,2]
[1,]    1         3
[2,]    2 142000760