Message-ID: <427982A4-477B-4A80-BE46-06A9FAFB32E2@win-vector.com>
Date: 2019-10-06T16:58:46Z
From: John Mount
Subject: should base R have a piping operator ?
In-Reply-To: <CAD4oTHHgSUr5TfLaTHxAM94E-Sqw9bW6gON7KdW324VEr524Lw@mail.gmail.com>
Except for the isolation of local() R pretty much already has the parsing transformation you mention.
as.list(parse(text="
iris ->.;
group_by(., Species) ->.;
summarize(., mean_sl = mean(Sepal.Length)) ->.;
filter(., mean_sl > 5)
"))
#> [[1]]
#> . <- iris
#>
#> [[2]]
#> . <- group_by(., Species)
#>
#> [[3]]
#> . <- summarize(., mean_sl = mean(Sepal.Length))
#>
#> [[4]]
#> filter(., mean_sl > 5)
<sup>Created on 2019-10-06 by the [reprex package](https://reprex.tidyverse.org) (v0.3.0)</sup>
> On Oct 5, 2019, at 4:50 PM, Gabriel Becker <gabembecker at gmail.com> wrote:
>
>
> iris %>% group_by(Species) %>% summarize(mean_sl = mean(Sepal.Length)) %>%
> filter(mean_sl > 5)
>
>
> were *parsed* as, for example, into
>
> local({
> . = group_by(iris, Species)
>
> ._tmp2 = summarize(., mean_sl = mean(Sepal.Length))
>
> filter(., mean_sl > 5)
> })
>
>
>
>
> Then debuggiing (once you knew that) would be much easier but behavaior
> would be the same as it is now. There could even be some sort of
> step-through-pipe debugger at that point added as well for additional
> convenience.
>
> There is some minor precedent for that type of transformative parsing:
>
>> expr = parse(text = "5 -> x")
>
>> expr
>
> expression(5 -> x)
>
>> expr[[1]]
>
> x <- 5
>
>
> Though thats a much more minor transformation.