#rstats users who’ve… uh, embraced 😅 the native pipe, how do you pipe into blocks you would’ve previously embraced (like ggplot calls)?

I’m really not thrilled with the anonymous function + native pipe combo, but I’m still deciding how much I trust using with…

My sense is that approach (d) (using with directly) essentially means ggplot2 sees aesthetics as raw vector columns, rather than passing the entire data frame into ggplot() and relying on its data-masking

It looks like there's a pipe-bind proposal to make something similar to javascript anonymous functions (but only for pipes), essentially expanding the placeholder idea into something more flexible.

It seems like it's been under discussion for a while though! I'm not sure if it's still planned.

https://stat.ethz.ch/pipermail/r-devel/2021-January/080396.html

https://stat.ethz.ch/pipermail/r-devel/2021-April/080646.html

[Rd] [External] brief update on the pipe operator in R-devel

@jimjamslam it's implemented! I'm on 4.1.2 and can enable it by setting an env var
@jonocarroll Oooh, nice! I'll have to experiment!
@jonocarroll @jimjamslam FYI - This may be going away.
@jonocarroll @jimjamslam Also there’s a package by @wiernik that replicates the functionality (minus the cool operator): https://github.com/bwiernik/pipebind
GitHub - bwiernik/pipebind: Flexible binding for complex function evaluation with the Base R |> pipe

Flexible binding for complex function evaluation with the Base R |> pipe - GitHub - bwiernik/pipebind: Flexible binding for complex function evaluation with the Base R |> pipe

GitHub

@kdpsingh @jonocarroll

That's a shame! I had a play this morning and really like it - although I admit I still don't have a great mental model of how it's working. It _seems_ like it's executing anonymous functions...

@jimjamslam @jonocarroll Yeah, the `=>` reminds me of the new Javascript anonymous function syntax, which I wish could work in R!
@jimjamslam boosting and bookmarking as I am interested in any answers!
@jimjamslam
I don't think I've ever piped into a code block before. In this particular example, can't you just pipe directly into ggplot and then start using + to join ggplot functions? See example in screenshot below which works as you might expect.
@cameronpat Interesting! It looks like piping in works due to operator precedence, but you can't pipe back out (eg. to save a plot).
@jimjamslam I use the first method, but without parentheses (I'm 99.9% sure they're not needed). I haven't used the native pipe so far, but if it doesn't let me do that, there are high chances that I will not start using it...

@jimjamslam I never piped (native or {magrittr}) or ever will into {ggplot2}.
For me it does not improve maintainability nor readability of the code. I would even say it’s the opposite and should be avoided.

#RStats #ggplot2 #magrittr

@MickaelCanouil That's fair! I can go a little long on pipes generally, and my difficulty here is probably a good signal that I ought to just break it off
@jimjamslam I basically have the following rules for pipes:
- Never pipe to {ggplot2}.
- only if calling strictly more than two functions except if it exceeds 80 characters
@jimjamslam also when a block involves >10 pipes for me it’s a sign some refactoring might be needed, i.e., merge multiple dplyr::mutate, use dplyr::select to select AND rename, etc.
@MickaelCanouil I break larger statements into named functions more anyway these days; ggplot calls are probably the main case where I’m still doing this!

@jimjamslam I just use both. I'm using {magrittr} for package dev anyway since it's backward compatible.

In other stuff, if I hit an edge case that doesn't work well with native pipe I just use the magrittr one. It's pretty rare though.

@jimjamslam although there's some data.table stuff for work which is almost exclusively magrittr. Another unfortunate side effect of the obsession with [].
@milesmcbain Yeah, most of my analyses still use the tidyverse, so there's no rush to switch. I gave it a spin on a recent targets project 😊
@jimjamslam why embrace here at all? Can just do
mtcars |> ggplot() + geom_point()
@wiernik You can't pipe back out (eg. to ggsave), unfortunately!

@jimjamslam ah that makes sense. That’s a situation where I usually assign a plot to a name before saving, so I hadn’t encountered it.

{pipebind} package might be good in this case

@wiernik yeah, it's probably a bad habit of mine tbh!