This code is working fine:
data.table::data.table(A = c(2, 1))[order(A), ]
It prints:
A
1: 1
2: 2
I can wrap this code inside a function just fine, too (same output):
bug <- function() {
data.table::data.table(A = c(2, 1))[order(A), ]
}
bug()
However, putting this function into a package and calling Bug::bug()does not work for some reason, giving me
Error in order(A) : object 'A' not found
Calls: <Anonymous> -> [ -> [.data.table -> [.data.frame -> order
Execution halted
Here is how to reproduce this problem:
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 into the directory where DESCRIPTION is and issue
R -e "devtools::document(); devtools::install(); Bug::bug()"