moodymudskipper / nakedpipe

Pipe Into a Sequence of Calls Without Repeating the Pipe Symbol.
69 stars 7 forks source link

right arrow assignment after ~~ #13

Closed daranzolin closed 4 years ago

daranzolin commented 4 years ago

It looks like right arrow assignment doesn't work after ~~. The first example using left arrow assignment works, but not the second. Reprex below:

library(nakedpipe)
suppressPackageStartupMessages(library(dplyr))
iris %.% {
  filter(Sepal.Length > 5)
  ~~ species_count <- count(., Species)
} -> iris_subset

iris %.% {
  filter(Sepal.Length > 5)
  ~~ count(., Species) -> species_count
} -> iris_subset
#> Error in eval_step(x, y, pf): Wrong syntax! If you mean to assign as a side effect you shoulduse a `~~` prefix

Created on 2020-03-26 by the reprex package (v0.3.0)

daranzolin commented 4 years ago

Interestingly though, it works with the %->% operator from zeallot:

library(zeallot)
library(nakedpipe)
suppressPackageStartupMessages(library(dplyr))
iris %.% {
  filter(Sepal.Length > 5)
  ~~ count(., Species) %->% species_count
} -> iris_subset
species_count
#> # A tibble: 3 x 2
#>   Species        n
#>   <fct>      <int>
#> 1 setosa        22
#> 2 versicolor    47
#> 3 virginica     49

Created on 2020-03-26 by the reprex package (v0.3.0)

moodymudskipper commented 4 years ago

It's because ~ has lower precedence than %->% but higher than <- so <- needs adhoc magic. Seems I forgot to support -> when implementing this magic but I believe it's an easy fix. Thanks for reporting!

moodymudskipper commented 4 years ago

now fixed!

github-actions[bot] commented 2 years ago

This old thread has been automatically locked. If you think you have found something related to this, please open a new issue and link to this old issue if necessary.