Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

all.equal on object with NULL names causes 'Error: not compatible with STRSXP' -- bug or expected?

Tags:

r

dplyr

In the example below, when names are set to NULL, all.equal throws 'Error: not compatible with STRSXP'
However, if names are set to NA (or some other value), all.equal works as normal.
Is this expected behavior or a bug?

## SAMPLE DATA
set.seed(1)
x <- data.frame(LETTERS[1:3], rnorm(3))
names(x) <- NULL

x
#   NA        NA
# 1  A -0.626454
# 2  B  0.183643
# 3  C -0.835629

all.equal(x, x)
# Error: not compatible with STRSXP

# add names back in, even 'NA'
names(x) <- c(NA, NA)
all.equal(x, x)
# [1] TRUE
like image 732
Ricardo Saporta Avatar asked Jan 27 '14 20:01

Ricardo Saporta


1 Answers

As @Joran points out, this seems to be related to dplyr. Filed as an issue: https://github.com/hadley/dplyr/issues/219

Temporary work around (for my need at least. Will not work for all) is to use

 all.equal.default(x, x)

FYI:

  ## STARTING FROM A FRESH SESSION:

  set.seed(1)
  x <- data.frame(LETTERS[1:3], rnorm(3))
  names(x) <- NULL

  all.equal(x, x)
  # [1] TRUE

  ## Load in dplyr
  library(dplyr)
  all.equal(x, x)
  # Error: not compatible with STRSXP
like image 86
Ricardo Saporta Avatar answered Nov 10 '22 01:11

Ricardo Saporta