gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 10:29:54 27 4
gpt4 key购买 nike

每当您尝试对 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/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com