r - 在未加载 data.table 包时使用 data.table 中的 `:=`?

标签 r data.table packages loading require

我想在不加载 data.table 的情况下使用 data.table 中的 := 运算符。例如对于下面的data.table,我想添加另一列名为error :

DT <- data.table::data.table(station = rep(1:1,52560), mod = rnorm(1*52560),obs = rnorm(1*52560))

但是,如果我执行以下操作,一切顺利,但我很困惑它是如何在不引用包 data.table 的情况下工作的(未加载 data.table 库)?!!
DT[ , `:=`(error  = mod - obs)]

如何使用 data.table::::= 重写上面的行?!!

最佳答案

不确定我理解正确,但关于:

I am going to use this in another package and preferably I want not to load data.table. – newbie

I am importing the package, I have no other choice since data.table will not work if I do not import. Would importing alone take care of this? – newbie



是导入 data.table 而不是依赖于你的包。您可能已经尝试过,但由于这个常见问题而没有奏效。请参阅此处的解决方案:

Using data.table package inside my own package

关于r - 在未加载 data.table 包时使用 data.table 中的 `:=`?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35352591/

相关文章:

r - 增加shinyBS popify 弹出窗口的宽度

r - 连接2个数据表同时汇总其中一个数据的最快方法

r - 性能提升

r - data.table 列子集返回 0 行

r - 如何重新安装base-R软件包(例如统计信息,图形,实用程序等)?

r - Vlookup-match like R 中的函数

r - R 中的 gsub() 不会替换 '.'(点)

packages - 什么是 Chocolatey "Install"包?

r - 在包检查 R 2.14.0 期间使用带有小插图的 inst/extdata

R igraph 遍历边列表并获取属性