问题描述
似乎 setDT
在您尝试在数据集
中存储的数据上运行时会返回错误。包。例如
library(data.table)
setDT(CO2)
##分配错误(name,x,parent.frame(),inherits = TRUE):
##无法更改'CO2'锁定绑定的值
最奇怪的是,如果你重新运行 setDT(CO2)
,它会工作
所以我查看了 setDT
的源代码,试图重现错误
x< - CO 2
name< - as.character(substitute(x))
assign(name,x,parent.frame = TRUE)
这样工作,没有返回任何错误。我的猜测是 parent.frame()
是导致它的那个,但我不能自己弄清楚后面的舞台。此外,我不明白为什么 setDT(CO2)
在第二次运行时不返回错误。
我的 sessionInfo()
## R版本3.0.3 2014-03-06)
##平台:x86_64-w64-mingw32 / x64(64位)
##
##区域设置:
## [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
##
##附带的基本包:
## [1] stats graphics grDevices utils数据集方法base
##
##其他附加包:
## [1] data.table_1.9.2
##
##通过命名空间加载(未附加):
## [1] plyr_1.8 reshape2_1.2.2 stringr_0.6.2 tools_3.0.3
解决方案/ 39e89521260d4d696e6befb82f922c692e1cb5efrel =nofollow> commit 1320 ,
setDT
现在返回一个友好的错误,即当绑定被锁定时,对象无法通过引用修改。从,No:37,修正了1.9.3的错误:
setDT
现在在尝试将变量更改为数据时提供了一个友好的错误。通过引用绑定被锁定(通常当变量在包中时,例如:CO2)。关闭。感谢David Arenburg在SO上提交报告。 p>
It seems like
setDT
returns an error whenever you are trying to run it on a stored data in thedatasets
package. For examplelibrary(data.table) setDT(CO2) ## Error in assign(name, x, parent.frame(), inherits = TRUE) : ## cannot change value of locked binding for 'CO2'
The strangiest thing is that if you rerun
setDT(CO2)
it will workSo I've looked in the source code of
setDT
and tried to reproduce the errorx <- CO2 name <- as.character(substitute(x)) assign(name, x, parent.frame(), inherits = TRUE)
Which worked and didn't return any error. My guess is that the
parent.frame()
is the one that causing it, but I can't figure out by myself whats going on back stage. Also, I can't understand whysetDT(CO2)
doesn't return an error on the second run.My
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
解决方案With commit 1320,
setDT
now returns a friendly error that the object can not be modified by reference when it's binding is locked. From 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.
这篇关于``setDT``从`data.table`包中出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!