[Rd] edge case concerning NA in dim() (PR#13729)

astokes at esica.com astokes at esica.com
Fri May 29 02:35:12 CEST 2009


Full_Name: Allan Stokes
Version: 28.1
OS: XP
Submission from: (NULL) (24.108.0.245)


I'm trying to use package HDF5 and have discovered some round-trip errors: save,
load, save is not idempotent.  I started digging into the type system to figure
out what type graffiti is fouling this up.  

Soon I discovered that comparisons with NULL produce zero length vectors, which
I hadn't known was possible, and I started to wonder about the properties of
zero length objects.  

L0 <- logical (0) 
dim(L0) <- c(0)  # OK 
dim(L0) <- c(1)  # error 
dim(L0) <- c(0,1) # OK 
dim(L0) <- c(0,-1) # OK 
dim(L0) <- c(0,3.14) # OK, c(0,3) results 
dim(L0) <- c(0,FALSE) # OK c(0,0) results 
dim(L0) <- c(0,NA) # OK 
dim(L0) <- c(1,NA) # error
dim(L0) <- c(1,NA,NA) # OK, SURPRISE!!   

NA*NA is normally NA, but in the test for dim() assignment, it appears that
NA*NA == 0, which is then allowed.  If the list contains more than one NA
elements, the product seems to evaluate to zero. 

I can see making a case for 0*NA == 0 in this context, but not for NA*NA == 0. 
As an aside, I'm not sure why 0*NA does not equal 0 in general evaluation,
unless NA is considered to possibly represent +/-inf.



More information about the R-devel mailing list