To use dtplyr, load dtplyr, dplyr, and optionally data.table. Use lazy_dt() to wrap a data frame into a "lazy" data table. This object tracks all subsequent dplyr operations without executing them immediately. To execute the operations and retrieve the results, use as.data.table(), as.data.frame(), or as_tibble().
library(data.table)
library(dtplyr)
library(dplyr, warn.conflicts = FALSE)
# Create a lazy data table
mtcars2 <- lazy_dt(mtcars)
# Perform transformations and execute to get a tibble
result <- mtcars2 %>%
filter(wt < 5) %>%
mutate(l100k = 235.21 / mpg) %>%
group_by(cyl) %>%
summarise(l100k = mean(l100k)) %>%
as_tibble()