Search code examples
rdplyrdata.tabledtplyr

R: Getting env_get_list error when trying to apply lazy_dt in order to use dtplyr


I'm trying to create a dashboard in R Shiny. As part of this dashboard, I have a very large dataset which has a column added reactively and in turn three reactive subsets of this dataset are produced by filtering on different dates.

So far, I have achieved the above via dplyr and using filter and mutate functions. However, I've noticed that it seems to be these points in the code that is slowing it down. It takes approx 10 seconds to process each table when any of the reactive variables are changed which trigger these tables to update. So I'm looking to speed this up.

I understand dplyr is much slower than data.table, but it is on the other hand, easier to understand the syntax. I'm also aware the dtplyr package exists to translate the dplyr code into data.table syntax, but I'm having trouble getting it to work.

I've been looking at the documentation and some youtube demonstrations, and as I understand it, it seems in order to use dtplyr, I need to use lazy_dt function to convert the table and then apply the standard dplyr functions to that table and then use the as.data.table() or as.tibble() command to convert it back to a data table.

However, the code isn't working, even though I've basically followed the exact same syntax as in the demonstration.

Here is some example code using the libraries I have imported in my main code, and which uses the iris dataset. It produces the following error at the print and as.data.table commands:

Error in env_get_list(ns_env("data.table"), dt_funs) : 
  argument "default" is missing, with no default

I can't work out what this error means or why it is happening. There is no "default" argument. The only required argument by lazy_dt is X, which is the dataset to be passed through it.

Here is the example code. I'm following this Youtube tutorial... https://www.youtube.com/watch?v=qwHHVU-NBLw ...You can see the first three lines of code after the libraries are exactly the same syntax as that in the video, but in the video the print function prints the table, but mine produces the error. Any ideas why? Note: I was getting this error even when applying this to my actual code, so it's not just because I'm trying to print the lazy_dt table.

library(shiny)
library(shinydashboard)
library(DT)
library(data.table)
library(dtplyr)
library(dplyr)
library(tidyverse)
library(Dict)
library(hash)
library(ModelMetrics)
library(vroom)
library(lubridate)
library(Rmisc)

iris_lazy <- dtplyr::lazy_dt(x=iris)

class(iris_lazy)

print(iris_lazy)

as.data.table(iris_lazy)

Solution

  • Try upgrading your version of data.table to >= 1.13.0. The minimum requirements of data.table will be updated in the next version of dtplyr.

    https://github.com/tidyverse/dtplyr/issues/224