R Inconsistencies

A collection of detected R inconsistencies and bugs.

Dimension inconsistencies

  1. Subsetting a matrix by selecting 0 rows and 0 columns preserves matrix format even without drop=FALSE.

    matrix()[1,0]                          matrix()[0,0]
    ## integer(0)                          ## <0 x 0 matrix>
    
  2. qnorm() drops matrix format when input is an empty matrix.

    qnorm(matrix(0.1, nrow=1, ncol=2))     qnorm(matrix(0.1, nrow=0, ncol=0))
    ##           [,1]      [,2]            ## numeric(0)
    ## [1,] -1.281552 -1.281552
    
  3. rbind() does not preserve the number of rows for data.frames, while cbind() does.

    mat <- matrix(nrow=2, ncol=0)
    df  <- as.data.frame(mat)
    
    
    dim(mat)                               dim(df)
    ## [1] 2 0                             ## [1] 2 0
    
    dim(cbind(mat, mat))                   dim(cbind(df, df))
    ## [1] 2 0                             ## [1] 2 0
    
    dim(rbind(mat, mat))                   dim(rbind(df, df))
    ## [1] 4 0                             ## [1] 0 0
    

    Number of columns are always preserved, making rbind and number of rows the only exception.

Type inconsistencies

  1. is.nan doesn’t work on data.frames while is.na does.

    is.na(iris)                            is.nan(iris)
    ## <works>                             ## <error>
    
  2. any() works on numeric data.frames but not on logical data.frames.

    any(data.frame(A=0, B=1))              any(data.frame(A=TRUE, B=FALSE))
    ## <warning>                           ## <error>
    ## TRUE
    
  3. rbind() on data.frame do not adjust row names to be unique when the data.frame is nested.

    df    <- data.frame(a=1:3)
    df$df <- data.frame(a=1:3)
    
    
    rbind(df, df)
    ## <error>
    

Hypothesis test inconsistencies

  1. Paired versions of wilcoxon.test() has tolerance issues when detecting if ties are present.

    wilcox.test(c(4,3,2), c(3,2,1), paired=TRUE)
    ## <warning about ties>
    
    
    wilcox.test(c(0.4,0.3,0.2), c(0.3,0.2,0.1), paired=TRUE)
    ## <no warning>
    
  2. Paired wilcox.test() throws an error about x when y observations are missing.

    wilcox.test(c(1,2), c(NA_integer_,NA_integer_), paired=TRUE)
    ## <error about not enough 'x' observations>
    
  3. var.test does not accept conf.level of either 0 or 1, while t.test does.

    t.test(rnorm(10), rnorm(10), conf.level=0)
    ## <works>
    
    
    var.test(rnorm(10), rnorm(10), conf.level=0)
    ## <error>
    

  1. ◦  Worth noting that this behaviour is documented in the manual pages of ?rbind.data.frame.