Kevin Schaul

Visual journalist/hacker

Speed up tidyverse analysis with dtplyr

March 21, 2023

I’ve got a ~15 million rows dataset that I need to do cleaning on. I’m a big tidyverse fan, but dplyr is slower than data.table.

Well, TIL about dtplyr, which lets you write dplyr code but gain the speed of data.table:

library(dplyr, warn.conflicts=FALSE)

data_lazy <- data %>%

data_lazy %>%
  mutate(...) %>%
  group_by(column) %>%
  summarize(...) %>%

Take a look at the immutable argument in the docs. This runs soooo much faster.

Pair that with a previous TIL about caching R code. Boom.