r - `setDT` 包中的 `data.table` 错误

标签 r data.table environment

每当您尝试对 datasets 包中存储的数据运行时,setDT 似乎都会返回错误。例如

library(data.table)
setDT(CO2)

## Error in assign(name, x, parent.frame(), inherits = TRUE) : 
##   cannot change value of locked binding for 'CO2'

最奇怪的是,如果你重新运行 setDT(CO2) 它会起作用

所以我查看了 setDT 的源代码并尝试重现错误

x <- CO2
name <- as.character(substitute(x))
assign(name, x, parent.frame(), inherits = TRUE)

哪个有效并且没有返回任何错误。我的猜测是 parent.frame() 是导致它的原因,但我自己无法弄清楚后台发生了什么。另外,我不明白为什么 setDT(CO2) 在第二次运行时没有返回错误。

我的sessionInfo()

## R version 3.0.3 (2014-03-06)
## Platform: x86_64-w64-mingw32/x64 (64-bit)
## 
## locale:
##   [1] LC_COLLATE=English_United States.1252  LC_CTYPE=English_United States.1252    LC_MONETARY=English_United States.1252
## [4] LC_NUMERIC=C                           LC_TIME=English_United States.1252    
## 
## attached base packages:
##   [1] stats     graphics  grDevices utils     datasets  methods   base     
## 
## other attached packages:
##   [1] data.table_1.9.2
## 
## loaded via a namespace (and not attached):
##   [1] plyr_1.8       reshape2_1.2.2 stringr_0.6.2  tools_3.0.3   

最佳答案

commit 1320 , setDT 现在返回一个友好的错误,即当对象的绑定(bind)被锁定时不能通过引用修改对象。来自 NEWS , No:37 under bug fixes for 1.9.3:

setDT now provides a friendly error when attempted to change a variable to data.table by reference whose binding is locked (usually when the variable is within a package, ex: CO2). Closes #475. Thanks to David Arenburg for filing the report here on SO.

关于r - `setDT` 包中的 `data.table` 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23361080/

相关文章:

r - 处理 R 中的字节顺序标记 (BOM)

r - 查找 data.table 中重复序列的最长长度和值

macos - R包安装在所有机器上成功,但一台

r - 从第二个数据帧注释 ggplot2

css - 带有 Shiny 主题机器人的 Shiny 数据表

development-environment - 在 PC 上的 VM 上开发的优缺点

testing - 如何为每次测试设置干净的测试机器

r - 在 R 的 matplot 中写入 $^*$

r - 快速计算允许自定义权重的移动平均/滚动函数的方法

python - 在哪里为 Django 项目设置 Python 环境属性?