[R] Potential Error/Bug?: addition of NULL during arithmetic

Eric DeWitt edewitt at hampshire.edu
Tue Aug 26 22:00:12 CEST 2008


I encountered an error that does not make sense to me given my reading 
of the documentation and does not appear to be referenced in the list 
archives or online. The error occurred when a function received a NULL 
value rather than a numeric value as a parameter and then attempted to 
use the NULL value in the calculateion. The error: "Error during wrapup: 
nothing to replace with" can be easily recreated with the following code:

> 1 + NULL  # note that the opperation succeeds and returns a numeric vector with dim(NULL)
numeric(0)

> bar <- 1
> bar
[1] 1
> foo <- 1 + NULL
> foo
numeric(0)

> bar <- bar + foo # note that here the assignment operation succeeds and 1 + (1 + NULL) -> numeric(0)
> bar
numeric(0)

> bar <- c(1, 1) # however if the assignment is into a vector
> bar[1] <- bar[1] + foo # note that the mathematical operation is identical, but the assignment fails
Error during wrapup: nothing to replace with

If this is the intended behavior, a more informative error message (e.g. 
'attempt to assign NULL to vector element') would be useful. If it is 
not the intended behavior, should I log this as a bug?

-eric

>sessionInfo()
R version 2.7.1 (2008-06-23) 
powerpc-apple-darwin8.10.1 

locale:
en_US.UTF-8/en_US.UTF-8/C/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base



More information about the R-help mailing list