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

boomer and grouped operations #93

Open
krlmlr opened this issue Jan 18, 2024 · 3 comments
Open

boomer and grouped operations #93

krlmlr opened this issue Jan 18, 2024 · 3 comments

Comments

@krlmlr
Copy link
Collaborator

krlmlr commented Jan 18, 2024

options(conflicts.policy = list(warn = FALSE))
library(dplyr)
tibble(a = 1:3) |>
  mutate(.by = a, b = a + 1) |>
  boomer::boom()
#> 💣 mutate(tibble(a = 1:3), .by = a, b = a + 1) 
#> · 💣 tibble(a = 1:3) 
#> · · 💣 💥 1:3 
#> · · [1] 1 2 3
#> · · 
#> · 💥 tibble(a = 1:3) 
#> · # A tibble: 3 × 1
#> ·       a
#> ·   <int>
#> · 1     1
#> · 2     2
#> · 3     3
#> · 
#> · 💣 💥 a + 1 
#> · [1] 2
#> · 
#> · 💣 💥 a + 1 
#> · [1] 3
#> · 
#> · 💣 💥 a + 1 
#> · [1] 4
#> · 
#> 💥 mutate(tibble(a = 1:3), .by = a, b = a + 1) 
#> # A tibble: 3 × 2
#>       a     b
#>   <int> <dbl>
#> 1     1     2
#> 2     2     3
#> 3     3     4
#> # A tibble: 3 × 2
#>       a     b
#>   <int> <dbl>
#> 1     1     2
#> 2     2     3
#> 3     3     4

Created on 2024-01-18 with reprex v2.0.2

I was only somewhat surprised to see the multiple invocations of a + 1 shown here, but for larger data this becomes difficult to review. If we collected the results (as suggested in #72), we could render as an HTML document or show in a Shiny app, and collapse/expand/filter as needed.

Alternatively, if there was a way to stop booming everything inside mutate(), those wouldn't be shown. options(boomer.ignore = "mutate") doesn't do the right thing here, do we need options(boomer.ignore.inside) ?

@moodymudskipper
Copy link
Owner

+ is the printing function here, that's why ignoring mutate doesn't work.

Maybe with options(boomer.ignore.inside = TRUE) when the function is entered the environment containing the shims could be dropped and set back on.exit.

Meanwhile maybe boom_on() and boom_off() can help

options(conflicts.policy = list(warn = FALSE))
library(dplyr)
library(boomer)
fun <- function() {
  boom_on()
  x <- tibble(a = 1:3)
  boom_off()
  mutate(x, .by = a, b = a + 1)
}
fun()
#> 💣 tibble(a = 1:3) 
#> · 💣 💥 1:3 
#> · [1] 1 2 3
#> · 
#> 💥 tibble(a = 1:3) 
#> # A tibble: 3 × 1
#>       a
#>   <int>
#> 1     1
#> 2     2
#> 3     3
#> 
#> 💣 💥 boom_off() 
#> NULL
#> # A tibble: 3 × 2
#>       a     b
#>   <int> <dbl>
#> 1     1     2
#> 2     2     3
#> 3     3     4

Created on 2024-01-18 with reprex v2.0.2

@krlmlr
Copy link
Collaborator Author

krlmlr commented Jan 18, 2024

Hm... I do want to see the results of the mutate() call.

@moodymudskipper
Copy link
Owner

OK I think I know how to do it, however, in the above call using the base pipe it's worth noting that the tibble call is also "inside", with the magrittr pipe it would be outside

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants