Currently select() always takes a deep copy. We can instead drop columns by reference if an implicit or explicit copy has already occurred in the pipe chain.
Waiting on #366
library(dplyr, warn.conflicts = FALSE)
library(dtplyr)
df <- lazy_dt(tibble(x = 1, y = 2))
# Old
df %>%
mutate(z = 3) %>%
select(x, z)
#> Source: local data table [1 x 2]
#> Call: copy(`_DT1`)[, `:=`(z = 3)][, .(x, z)]
#>
#> x z
#> <dbl> <dbl>
#> 1 1 3
#>
#> # Use as.data.table()/as.data.frame()/as_tibble() to access results
# New
remove_vars <- dtplyr:::remove_vars
df %>%
mutate(z = 3) %>%
remove_vars("y")
#> Source: local data table [1 x 2]
#> Call: copy(`_DT1`)[, `:=`(z = 3)][, `:=`("y", NULL)]
#>
#> x z
#> <dbl> <dbl>
#> 1 1 3
#>
#> # Use as.data.table()/as.data.frame()/as_tibble() to access results
Currently
select()always takes a deep copy. We can instead drop columns by reference if an implicit or explicit copy has already occurred in the pipe chain.Waiting on #366