Sparklyr fails when using a case_when
with external variables.
Working Example:
test <- copy_to(sc, tibble(column = c(1,2,3,4)))
test %>%
mutate(group = case_when(
column %in% c(1,2) ~ 'group 1',
column %in% c(3,4) ~ 'group 2'))
Fails with Error: Can't extract an environment from NULL
test <- copy_to(sc, tibble(column = c(1,2,3,4)))
group1_cols <- c(1,2)
group2_cols <- c(3,4)
test %>%
mutate(group = case_when(
column %in% group1_cols ~ 'group 1',
column %in% group2_cols ~ 'group 2'))
Try unquoting the variables:
test %>%
mutate(group = case_when(
column %in% !!group1_cols ~ 'group 1',
column %in% !!group2_cols ~ 'group 2'))
For more info check out the dplyr
programming vignette http://dplyr.tidyverse.org/articles/programming.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With