tracing everything step-by-step in multi-line R scripts and not just the final pipe expression
it would be good to eventually handle multi-line R scripts so that mario isn't restricted to analyzing a single pipeline expression
I think we will get this for free with the new environment setup.
On Tue, Nov 2, 2021 at 4:29 PM pgbovine @.***> wrote:
it would be good to eventually handle multi-line R scripts so that mario isn't restricted to analyzing a single pipeline expression
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/seankross/mario/issues/12, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAN4JJLWUGZWTNDYPQXOYA3UKB65PANCNFSM5HHUFX6A .
good! we need users to be able to run small, self-contained examples where they make up their own tibbles on separate lines instead of just doing a one-liner pipe on an existing dataset. there are a bunch of these examples in docs/tutorials, like: https://dplyr.tidyverse.org/reference/mutate.html
# By default, new columns are placed on the far right.
# Experimental: you can override with `.before` or `.after`
df <- tibble(x = 1, y = 2)
df %>% mutate(z = x + y)
#> # A tibble: 1 x 3
#> x y z
#> <dbl> <dbl> <dbl>
#> 1 1 2 3
df %>% mutate(z = x + y, .before = 1)
#> # A tibble: 1 x 3
#> z x y
#> <dbl> <dbl> <dbl>
#> 1 3 1 2
df %>% mutate(z = x + y, .after = x)
#> # A tibble: 1 x 3
#> x z y
#> <dbl> <dbl> <dbl>
#> 1 1 3 2
# By default, mutate() keeps all columns from the input data.
# Experimental: You can override with `.keep`
df <- tibble(x = 1, y = 2, a = "a", b = "b")
df %>% mutate(z = x + y, .keep = "all") # the default
#> # A tibble: 1 x 5
#> x y a b z
#> <dbl> <dbl> <chr> <chr> <dbl>
#> 1 1 2 a b 3
df %>% mutate(z = x + y, .keep = "used")
#> # A tibble: 1 x 3
#> x y z
#> <dbl> <dbl> <dbl>
#> 1 1 2 3
df %>% mutate(z = x + y, .keep = "unused")
#> # A tibble: 1 x 3
#> a b z
#> <chr> <chr> <dbl>
#> 1 a b 3
df %>% mutate(z = x + y, .keep = "none") # same as transmute()
#> # A tibble: 1 x 1
#> z
#> <dbl>
#> 1 3
This is also important for instructors teaching how pipes are really just syntactic sugar for regular non-pipe operations. for instance, this is pipe-y and now works:
starwars %>%
filter(hair_color == "none",
eye_color == "black" | sex == "male",
homeworld == "Tatooine" | homeworld == "Bespin") %>%
select(name, height)
But we want the non-pipey equivalent to do something sensible as well:
x <- filter(starwars, hair_color == "none", eye_color == "black" | sex == "male", homeworld == "Tatooine" | homeworld == "Bespin")
y <- select(x, name, height)
y
This sorta works now, but it gives inconsistent results if the last line isn't a pipe expression: https://github.com/seankross/mario/issues/19
I think for the first version of mario, it's fine to have it scoped to pipes. One vision for the future is to have it actually display what's going on in ALL EXPRESSIONS in the user's code step by step, not just the final one. But that risks feature creep for now, so don't worry about it for now.