本文介绍了对于具有NULL名称的对象的all.equal导致“错误:与STRSXP不兼容” - 错误或预期?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在下面的示例中,当名称设置为 NULL
时, all.equal
throws 错误:与STRSXP不兼容
但是,如果名称设置为 NA
(或其他一些值) , all.equal
正常工作。
这是预期的行为还是一个错误?
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
推荐答案
正如@Joran指出的,这似乎与 dplyr
。
提出问题:
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: / p>
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
这篇关于对于具有NULL名称的对象的all.equal导致“错误:与STRSXP不兼容” - 错误或预期?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!