Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert transmute() to use mutate(.keep = "none") #470

Open
markfairbanks opened this issue Feb 26, 2024 · 2 comments · May be fixed by #483
Open

Convert transmute() to use mutate(.keep = "none") #470

markfairbanks opened this issue Feb 26, 2024 · 2 comments · May be fixed by #483
Labels
internals internal update

Comments

@markfairbanks
Copy link
Collaborator

This will improve performance by preventing unnecessary copies in longer pipe chains.

@markfairbanks markfairbanks added the internals internal update label Feb 26, 2024
@eutwt
Copy link
Collaborator

eutwt commented Feb 26, 2024

Is this possible while allowing transmute() to produce an output with a different number of rows?

This would also fix the fact that transmute() should have the same number of rows but currently doesn't. We just need a column reorder after the mutate.

mtcars %>% 
  lazy_dt() %>% 
  transmute(hp = 1, mpg = 2)
#> Source: local data table [1 x 2]
#> Call:   `_DT4`[, .(hp = 1, mpg = 2)]
#> 
#>      hp   mpg
#>   <dbl> <dbl>
#> 1     1     2
#> 
#> # Use as.data.table()/as.data.frame()/as_tibble() to access results

mtcars %>% 
  lazy_dt() %>% 
  mutate(hp = 1, mpg = 2, .keep = 'none')
#> Source: local data table [32 x 2]
#> Call:   copy(`_DT5`)[, `:=`(hp = 1, mpg = 2)][, `:=`(c("cyl", "disp", 
#> "drat", "wt", "qsec", "vs", "am", "gear", "carb"), NULL)]
#> 
#>      mpg    hp
#>    <dbl> <dbl>
#>  1     2     1
#>  2     2     1
#>  3     2     1
#>  4     2     1
#>  5     2     1
#>  6     2     1
#>  7     2     1
#>  8     2     1
#>  9     2     1
#> 10     2     1
#> # ℹ 22 more rows
#> 
#> # Use as.data.table()/as.data.frame()/as_tibble() to access results

@markfairbanks
Copy link
Collaborator Author

Yep you're right. Looks like as-is it's basically a summarize()/reframe() call.

pacman::p_load(dtplyr, dplyr)

data <- data.frame(x = c("A", "A", "B", "B"), y = c(1, 2, 3, 4))

lazy_dt(data) %>%
  transmute(mean_y = mean(y))
#> Source: local data table [1 x 1]
#> Call:   `_DT1`[, .(mean_y = mean(y))]
#> 
#>   mean_y
#>    <dbl>
#> 1    2.5
#> 
#> # Use as.data.table()/as.data.frame()/as_tibble() to access results

@markfairbanks markfairbanks linked a pull request Dec 10, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
internals internal update
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants