[Rd] suggestion with ambiguous object component replacement

Benjamin Tyner btyner at gmail.com
Fri Aug 10 22:47:19 CEST 2007


?"[<-" says

"When replacing (that is using indexing on the lhs of an assignment)
NA does not select any element to be replaced. As there is ambiguity
as to whether an element of the rhs should be used or not, this is
only allowed if the rhs value is of length one (so the two
interpretations would have the same outcome)."

This is quite reasonable to me; for example,

letters[NA] <- "z"

does not throw an error but

letters[NA] <- c("z","z")

does. However I wonder why assignments like

letters[c(2,2)] <- c("b1","b2")

are allowed, since at least to me it is not clear at all that "b2" is
the intended replacement. I would think that at the very least this
should throw a warning. I apologize if this has already been
discussed.

Thanks
Ben



More information about the R-devel mailing list