Closed eipi10 closed 2 years ago
This is because of a quirk with how data.table
works. Even though dtplyr
is using data.table
, you also need to specify in your package that data.table
is being used.
To do this you need to define an environment variable .datatable.aware <- TRUE
once somewhere in your package.
#' @export
my_fnc = function(x) {
x %>%
lazy_dt() %>%
group_by(id, year) %>%
summarise(across(matches("^v"), sum)) %>%
as_tibble()
}
.datatable.aware <- TRUE
@hadley already submitted a fix for this to data.table
, and we're just waiting for their next release to CRAN (hopefully sometime in the next few months).
You can track the issue from our end here.
I'm going to close this issue, but if you have any questions let me know.
I'm glad it was an easy fix. Thanks for your help!
I'm trying to use
dtplyr
to speed up some functions in a personal package. However, I'm finding that code and functions that run properly when defined in a local session, give an error when defined in a package. If I have the package importdata.table
(by adding@import data.table
) then the error goes away, but I thoughtdata.table
didn't need to be loaded fordtplyr
to work.Here's a reprex (except for the fact that you don't have access to the package, but I show below the how the function is defined in the package):
Created on 2022-11-10 with reprex v2.0.2