这段代码工作正常:
data.table::data.table(A = c(2, 1))[order(A), ]
它打印:
A
1: 1
2: 2
我也可以将此代码封装在函数中(相同的输出):
bug <- function() {
data.table::data.table(A = c(2, 1))[order(A), ]
}
bug()
但是,将此函数放入包中并调用Bug::bug()
由于某种原因不起作用,给我
Error in order(A) : object 'A' not found
Calls: <Anonymous> -> [ -> [.data.table -> [.data.frame -> order
Execution halted
以下是重现此问题的方法:
File DESCRIPTION
:
Package: Bug
Title: Bug
Version: 0.0.0.0001
Description: Bug
License: GPLv3
Imports: data.table
Encoding: UTF-8
RoxygenNote: 7.1.1
File R/Bug.R
:
#' @export
bug <- function() {
data.table::data.table(A = c(2, 1))[order(A), ]
}
Then cd
进入目录DESCRIPTION
是和问题
R -e "devtools::document(); devtools::install(); Bug::bug()"