-
Notifications
You must be signed in to change notification settings - Fork 60
Closed
Description
library(dplyr, warn.conflicts = FALSE)
library(dtplyr)
df <- tibble(x = 1) %>% group_by(x)
# grouping variable cannot be selected
df %>%
lazy_dt() %>%
transmute(y = 2) %>%
.$vars
#> [1] "y"
df %>%
transmute(y = 2)
#> # A tibble: 1 x 2
#> # Groups: x [1]
#> x y
#> <dbl> <dbl>
#> 1 1 2
# transmuting a grouping variable
df %>%
lazy_dt() %>%
transmute(x = x + 1, y = 2)
#> Source: local data table [1 x 3]
#> Groups: x
#> Call: `_DT2`[, .(x = x + 1, y = 2), keyby = .(x)]
#>
#> x x y
#> <dbl> <dbl> <dbl>
#> 1 1 2 2
#>
#> # Use as.data.table()/as.data.frame()/as_tibble() to access results
df %>%
transmute(x = x + 1, y = 2)
#> # A tibble: 1 x 2
#> # Groups: x [1]
#> x y
#> <dbl> <dbl>
#> 1 2 2
# mutating works correctly
df %>%
lazy_dt() %>%
mutate(x = x + 1, y = 2)
#> Source: local data table [1 x 2]
#> Groups: x
#> Call: copy(`_DT3`)[, `:=`(x = x + 1, y = 2), by = .(x)]
#>
#> x y
#> <dbl> <dbl>
#> 1 2 2
#>
#> # Use as.data.table()/as.data.frame()/as_tibble() to access results
df %>%
mutate(x = x + 1, y = 2)
#> # A tibble: 1 x 2
#> # Groups: x [1]
#> x y
#> <dbl> <dbl>
#> 1 2 2
# grouping variable cannot be renamed
lazy_dt(tibble(x = 1, y = 2)) %>%
group_by(z = x) %>%
summarise(y = mean(y)) %>%
show_query()
#> `_DT4`[, .(y = mean(y)), keyby = .(z)]
tibble(x = 1, y = 2) %>%
group_by(z = x) %>%
summarise(y = mean(y))
#> # A tibble: 1 x 2
#> z y
#> <dbl> <dbl>
#> 1 1 2Created on 2021-05-19 by the reprex package (v2.0.0)
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels