[Rd] No error when assigning values to an "empty" vector/matrix/array

S Ellison S.Ellison at LGCGroup.com
Fri Oct 24 15:58:06 CEST 2014

> > Also note that these warnings or errors are complaining that the
> > number of items to replace (left length) is not a multiple of
> > replacement length (right length). This suggests that when the left
> > length is a multiple of the right length, everything is fine.
> > And this is actually the case when the left length is 0. Because
> > 0 is a multiple of anything. So in that case, the right value is
> > truncated to length 0 and no warning is issued. Makes sense to me.
> Thanks Hervé, you gave the perfect explanation/rationale for this being
> consistent.

This explains why a check for exact multiple of replacement length does not trigger a warning, but surely that is not sensible in the length 0 case. In all other cases, this check warns when there will be truncation of the replacement, and that seems to me the sensible intent of the check. A silent truncation to nothing is surely not the intended behaviour.
I can't help feeling that the 'check for multiple of length' was a neat portmanteau check for several possible problems when recycling is allowed, but that the possibility of assigning to a length 0 object was not considered.

I'd suggest logging it as an issue to for R-core to at least look at and either to fix or to at least warn of in documentation.

S Ellison

This email and any attachments are confidential. Any use, copying or
disclosure other than by the intended recipient is unauthorised. If 
you have received this message in error, please notify the sender 
immediately via +44(0)20 8943 7000 or notify postmaster at lgcgroup.com 
and delete this message and any copies from your computer and network. 
LGC Limited. Registered in England 2991879. 
Registered office: Queens Road, Teddington, Middlesex, TW11 0LY, UK

More information about the R-devel mailing list