Skip to content
Prev 325767 / 398503 Next

Nulls being coerced : Bug or design?

On Jun 21, 2013, at 1:21 PM, Saptarshi Guha wrote:

            
This seems like a bizarre expectation. You really want x to remain NULL until the end of time? Perhaps you meant to say that after creation of a tenth entry for x that you wanted x[1] to remain NULL (which it never was, since it didn't really exist). Or to have the display of missing values to be suppressed by the print function? Or were hoping the creation of an n-th item in x to _not_ create a vector of length n? Or that `x` be different than a multi-valued version of x[n]?
[1] 10
168 bytes
8040 bytes

So you have apparently not realized that lists in R are actually vectors. .... by design. And the indexing a NULL value gives NULL rather than missing (NA):

x <- NULL
NULL
NULL
NULL
NULL
[1] NA

Actually I think the behavior for "[" when indexing is attempted with arguments greater than the length of a list or vector is not at all what I would have expected. That it would have seem to me to have deserved a NULL return:
[1] NA