Despite specifying immutable=TRUE in lazy_dt, if I have a mutate followed by a summarize followed by a mutate, the first mutate will get applied to the input data.table object, when it should not be modified. I can't seem to trigger it unless I have a mutate after the summarize.
library(data.table)
library(dtplyr)
library(dplyr)
#>
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:data.table':
#>
#> between, first, last
#> The following objects are masked from 'package:stats':
#>
#> filter, lag
#> The following objects are masked from 'package:base':
#>
#> intersect, setdiff, setequal, union
d1= data.table(x=c(1,1,1,2,2,2), y=c(1,2,3,4,5,6))
d2 = lazy_dt(d1, immutable = TRUE) %>%
mutate(
y=-y,
z = x+y
) %>%
summarize(
mean_y = mean(y),
mean_z = mean(z)
) %>%
mutate(
sum_mean = mean_y + mean_z
) %>%
as.data.table()
d1
#> x y z
#> 1: 1 -1 0
#> 2: 1 -2 -1
#> 3: 1 -3 -2
#> 4: 2 -4 -2
#> 5: 2 -5 -3
#> 6: 2 -6 -4
Details
Here's my sessionInfo():
R version 4.0.3 (2020-10-10)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19042)
Matrix products: default
locale:
[1] LC_COLLATE=English_Canada.1252 LC_CTYPE=English_Canada.1252 LC_MONETARY=English_Canada.1252 LC_NUMERIC=C
[5] LC_TIME=English_Canada.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] dplyr_1.0.3 dtplyr_1.1.0 data.table_1.13.6
loaded via a namespace (and not attached):
[1] assertthat_0.2.1 crayon_1.4.0 R6_2.5.0 DBI_1.1.1 lifecycle_0.2.0 magrittr_2.0.1 pillar_1.4.7 rlang_0.4.10
[9] vctrs_0.3.6 generics_0.1.0 ellipsis_0.3.1 tools_4.0.3 glue_1.4.2 purrr_0.3.4 compiler_4.0.3 pkgconfig_2.0.3
[17] tidyselect_1.1.0 tibble_3.0.5
Despite specifying
immutable=TRUEinlazy_dt, if I have amutatefollowed by asummarizefollowed by amutate, the firstmutatewill get applied to the input data.table object, when it should not be modified. I can't seem to trigger it unless I have amutateafter thesummarize.Details
Here's my
sessionInfo():