`expss` 和 `data.table` 不能一起玩
Posted
技术标签:
【中文标题】`expss` 和 `data.table` 不能一起玩【英文标题】:`expss` and `data.table` not playing well together 【发布时间】:2018-12-07 15:42:47 【问题描述】:我正在使用 expss
包为调查数据生成横幅表,但我不断收到一个在 Google 上不会出现的错误:Error in data.table(cell_var, col_var, row_var) : object '.R.listCopiesNamed' not found
。
我在下面创建了一个可重现的示例。我不清楚这是来自expss
还是来自data.table
的错误,还是来自两者的组合。无论如何,有没有办法覆盖对'.R.listCopiesNamed'
的需求,或者其他解决错误的方法?
我在这种环境中工作:R version 3.4.4 (2018-03-15) -- "Someone to Lean On"
Copyright (C) 2018 The R Foundation for Statistical Computing
Platform: x86_64-apple-darwin15.6.0 (64-bit)
可重现的例子:
# load packages
library(expss)
library(tidyverse)
# generate some data
set.seed(369)
age <- base::sample(c("18-24", "25-24", "35-44", "45-54", "55-64", "65+"),
100, replace = TRUE)
sex <- base::sample(c("Male", "Female"),
100, replace = TRUE)
likelihood <- base::sample(c("Much more likely", "Somewhat more likely",
"Equally likely", "Somewhat less likely",
"Much less likely"), 100, replace = TRUE)
importance <- base::sample(c("Extremely important", "Somewhat important",
"Neutral", "Somewhat unimportant",
"Extremely unimportant"), 100, replace = TRUE)
relevance <- base::sample(c("Extremely relevant", "Somewhat relevant",
"Neutral", "Somewhat irrelevant",
"Extremely irrelevant"), 100, replace = TRUE)
data <- data.frame(age, sex, likelihood, importance, relevance)
# make a simple banner table with significance testing
myTable <- data %>%
tab_cells(likelihood, importance, relevance) %>%
tab_cols(total(), age, sex) %>%
tab_stat_cpct() %>%
tab_last_sig_cpct() %>%
tab_pivot()
此时,我收到错误消息:Error in data.table(cell_var, col_var, row_var) :
object '.R.listCopiesNamed' not found
~~~~~~~
编辑添加 traceback() 和 sessionInfo():
> traceback()
19: data.table(cell_var, col_var, row_var)
18: make_datatable_for_cro(cell_var = cell_var, col_var = col_var,
row_var = row_var, weight = weight, subgroup = subgroup)
17: elementary_cro(cell_var = each_cell_var, col_var = each_col_var,
row_var = each_row_var, weight = weight, subgroup = subgroup,
total_label = total_label, total_statistic = total_statistic,
total_row_position = total_row_position, stat_type = stat_type)
16: FUN(X[[i]], ...)
15: lapply(col_vars, function(each_col_var)
elementary_cro(cell_var = each_cell_var, col_var = each_col_var,
row_var = each_row_var, weight = weight, subgroup = subgroup,
total_label = total_label, total_statistic = total_statistic,
total_row_position = total_row_position, stat_type = stat_type)
)
14: FUN(X[[i]], ...)
13: lapply(cell_vars, function(each_cell_var)
all_col_vars = lapply(col_vars, function(each_col_var)
elementary_cro(cell_var = each_cell_var, col_var = each_col_var,
row_var = each_row_var, weight = weight, subgroup = subgroup,
total_label = total_label, total_statistic = total_statistic,
total_row_position = total_row_position, stat_type = stat_type)
)
Reduce(merge, all_col_vars)
)
12: FUN(X[[i]], ...)
11: lapply(row_vars, function(each_row_var)
res = lapply(cell_vars, function(each_cell_var)
all_col_vars = lapply(col_vars, function(each_col_var)
elementary_cro(cell_var = each_cell_var, col_var = each_col_var,
row_var = each_row_var, weight = weight, subgroup = subgroup,
total_label = total_label, total_statistic = total_statistic,
total_row_position = total_row_position, stat_type = stat_type)
)
Reduce(merge, all_col_vars)
)
res = do.call(add_rows, res)
)
10: multi_cro(cell_vars = cell_vars, col_vars = col_vars, row_vars = row_vars,
weight = weight, subgroup = subgroup, total_label = total_label,
total_statistic = total_statistic, total_row_position = total_row_position,
stat_type = "cpct")
9: cro_cpct(cell_vars = get_cells(data), col_vars = data[[COL_VAR]],
row_vars = data[[ROW_VAR]], weight = data[[WEIGHT]], subgroup =
data[[SUBGROUP]],
total_label = total_label, total_statistic = total_statistic,
total_row_position = total_row_position)
8: tab_stat_cpct(.)
7: function_list[[i]](value)
6: freduce(value, `_function_list`)
5: `_fseq`(`_lhs`)
4: eval(quote(`_fseq`(`_lhs`)), env, env)
3: eval(quote(`_fseq`(`_lhs`)), env, env)
2: withVisible(eval(quote(`_fseq`(`_lhs`)), env, env))
1: data %>% tab_cells(likelihood, importance, relevance) %>% tab_cols(total(),
age, sex) %>% tab_stat_cpct() %>% tab_last_sig_cpct() %>%
tab_pivot()
> sessionInfo()
R version 3.4.4 (2018-03-15)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS Sierra 10.12.6
Matrix products: default
BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK:
/Library/Frameworks/R.framework/Versions/3.4/Resources/lib/libRlapack.dylib
locale:
[1] en_CA.UTF-8/en_CA.UTF-8/en_CA.UTF-8/C/en_CA.UTF-8/en_CA.UTF-8
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] expss_0.8.6
loaded via a namespace (and not attached):
[1] Rcpp_0.12.17 matrixStats_0.53.1 digest_0.6.15 backports_1.1.2
[5] magrittr_1.5 stringi_1.1.6 data.table_1.11.4 rstudioapi_0.7
[9] checkmate_1.8.5 tools_3.4.4 stringr_1.3.0 foreign_0.8-69
[13] htmlwidgets_1.2 yaml_2.1.17 compiler_3.4.4 htmltools_0.3.6
[17] knitr_1.20 htmlTable_1.11.2
【问题讨论】:
你能在这个错误之后运行 traceback() 吗?并且还包括你的包版本 它对我有用。就像迈克尔说的那样,要么是版本上的一些 tidyverse 碰撞。无论如何,你在这里加载 tidyverse 是为了什么?你根本没有在这里使用它。 @DavidArenburg 我只是在没有加载 tidyverse 的情况下运行了代码,得到了同样的错误。无论如何,我会在现实世界中加载 tidyverse,所以如果它引起了干扰,那么了解这一点很重要。 (但似乎 tidyverse 不是导致此错误的原因。) @MichaelChirico 我已将 traceback() 和 systemInfo() 添加到问题中。现在更新我的包,看看是不是这个问题。 @MichaelChirico 确实是软件包版本——感谢您指出这一点! 【参考方案1】:解决方案:更新expss
包。感谢@MichaelChirico 的建议!
【讨论】:
以上是关于`expss` 和 `data.table` 不能一起玩的主要内容,如果未能解决你的问题,请参考以下文章