Skip to content

Fast select() #367

Description

@markfairbanks

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions