R: Added import(data.table) to NAMESPACE automatically using devtools

ⅰ亾dé卋堺 提交于 2019-12-11 03:26:23

问题


How do I correctly add import(data.table) to the NAMESPACE file automatically using devtools?

Generally if my packages use data.table I just write it in manually, but then I can't use @export and devtools::document to create the NAMESPACE file properly, as it either overwrites the addition I've made, or doesn't update the file at all.

Plus, it says not edit it manually...

Thanks


Sample package/R/function.R code

#' @export
#' @import data.table
test_data_table = function(dt) {
  dt[, a := 3]
}

Call example

> test_data_table
function(dt) {
  dt[, a := 3]
}
<environment: namespace:package>

> test_data_table(dt)
 Show Traceback

 Rerun with Debug
 Error in `[.data.frame`(x, i, j) : could not find function ":=" 

回答1:


You probably shouldn't use import(*) at all, unless you really need every exported object from a package. Instead, use importFrom(pkg, obj1, obj2, ...) to import only those objects you need.

From the Writing R Extensions manual, S1.5.1:

Using importFrom selectively rather than import is good practice and recommended notably when importing from packages with more than a dozen exports.

Nonetheless, if you do need to import everything, use #' @import data.table.



来源:https://stackoverflow.com/questions/40888820/r-added-importdata-table-to-namespace-automatically-using-devtools

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!