I use RStudio Workbench. When I create a simple function like that:
sample <- function() {
df <- data.frame('a' = c(1:10), 'b' = c(1:10))
dt <- data.table::as.data.table(df)
return (dt[, .(b)])
}
all is fine. When I call this with sample(), there is no error. The package "data.table" is available in the system library. I didn't load it with library().
When I use "devtools" to create a package. Then I get the error: Error in .(b) : could not find function "."
Here is the flow to reproduce the error:
Create the package directory with:
devtools::create('home/development/sample', rstudio = FALSE)
Save the file "sample.R" in the R directory.
#' Example
#'
#' Where is the problem?
#'
#' @return Column 'b' from a data table.
#'
#' @examples
#' \code{sample()}
#'
#' @export
sample <- function() {
df <- data.frame('a' = c(1:10), 'b' = c(1:10))
dt <- data.table::as.data.table(df)
return (dt[, .(b)])
}
Document the package and load it.
devtools::document('home/development/sample')
devtools::load_all('home/development/sample', export_all = FALSE, reset = TRUE)
sample::sample()
# Console: Error in .(b) : could not find function "."
Where could be the problem? Is anything to do with devtools? E.g. with the DESCRIPTION file? I use data.table with data.table::name() and he used in the global environment the .() syntax. But not with the package? Where I have to load it? Thanks for your help in advance.