Bug 14959 - Error or wrong return type in is.na.data.frame() when input has zero columns
Error or wrong return type in is.na.data.frame() when input has zero columns
Product: R
Classification: Unclassified
Component: Misc
R 2.15.0 patched
x86_64/x64/amd64 (64-bit) Linux
: P5 normal
Assigned To: R-core
Depends on:
  Show dependency treegraph
Reported: 2012-06-25 14:19 UTC by Mikko Korpela
Modified: 2012-06-26 10:49 UTC (History)
0 users

See Also:


Note You need to log in before you can comment on or make changes to this bug.
Description Mikko Korpela 2012-06-25 14:19:39 UTC

When given a data.frame with zero columns, is.na() either fails or gives a result of the wrong type, depending on whether the input has row.names.

Note: This is about R 2.15.1 patched (option not available in the report form).

Steps To Reproduce

foo.df <- as.data.frame(matrix(nrow=26, ncol=0, dimnames=list(letters)))
row.names(foo.df) <- NULL

Actual Results

The first instance of is.na(foo.df) gives an error:

Error in `rownames<-`(`*tmp*`, value = row.names(x)) : 
  attempt to set rownames on object with no dimensions

and a further traceback() gives:

4: stop("attempt to set rownames on object with no dimensions")
3: `rownames<-`(`*tmp*`, value = row.names(x))
2: is.na.data.frame(foo.df)
1: is.na(foo.df)

The second instance of is.na(foo.df), after setting row.names to NULL, returns NULL

Expected Results

Both instances of is.na(foo.df) above should return a logical matrix with 26 rows and 0 columns. From ?is.na:

     The method ‘is.na.data.frame’ returns a logical matrix with the
     same dimensions as the data frame, and with dimnames taken from
     the row and column names of the data frame.

Build Date & Platform

> sessionInfo()
R version 2.15.1 Patched (2012-06-24 r59622)
Platform: x86_64-unknown-linux-gnu (64-bit)

 [1] LC_CTYPE=en_US.utf8       LC_NUMERIC=C             
 [3] LC_TIME=en_US.utf8        LC_COLLATE=en_US.utf8    
 [5] LC_MONETARY=en_US.utf8    LC_MESSAGES=en_US.utf8   
 [7] LC_PAPER=C                LC_NAME=C                
 [9] LC_ADDRESS=C              LC_TELEPHONE=C           

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

loaded via a namespace (and not attached):
[1] tools_2.15.1