by wenc on 12/5/2020, 6:42:40 PM
by cwyers on 12/5/2020, 8:11:27 PM
The R "userland" pipe magrittr has been altered to make it more compatible with the proposed base pipe, as well:
https://www.tidyverse.org/blog/2020/11/magrittr-2-0-is-here/
by burlesona on 12/5/2020, 6:37:17 PM
That backslash syntax is pretty funky, but then again all of R is a little funky. Very nice addition to the language though!
by bluenose69 on 12/5/2020, 6:50:04 PM
These will both come in pretty handy, although the first is just a formalization of something that's already available in packages, the lambda syntax will clean up code a fair bit, and make realtime analysis easier to type.
by saeranv on 12/5/2020, 11:07:14 PM
Question by someone who is ignorant but interested in functional programming: what is the closest equivalent to these functions in Python? (Or correct me if I'm asking the wrong question).
I used to love using lambdas in Python, along with map/reduce/filter but for whatever reason the Python community has turned against it. Map and filter can now be nicely done with list comprehensions, although I still haven't found a decent one-line equivalent for reduce (other then importing functools).
by identity0 on 12/5/2020, 11:03:52 PM
I wish more languages gave us a "|>" operator. Too many languages settle with dot notation, which confuses encapsulation/method calling with syntactical convenience.
by wodenokoto on 12/5/2020, 6:52:54 PM
Kind of odd they didn't decide to go with the magrittr syntax, which is in common use and heavily promoted in dplyr / tidyverse.
I wonder if RStudio will change its `ctrl` + `shift` + m shortcut from the magrittr ( %>% ) style pipes to these new pipes ( |> )
by civilized on 12/5/2020, 7:15:41 PM
This sounds promising, but how do we type that pipe easily if we're going to be using it all the time? I actually like %>% because it's easy to reach the keys and hammer it out. Agreed on the ugly stack traces.
by tpoacher on 12/6/2020, 3:27:41 PM
For people asking how one could possibly ever manage to chain operations in python without a pipe operator: https://github.com/tpapastylianou/chain-ops-python
Same principle in octave: https://github.com/tpapastylianou/chain-ops-octave
by kgwgk on 12/5/2020, 7:51:48 PM
The lambda thing may be useful. Sometimes I was tempted to do something like this
> f <- function(expr) eval(substitute( function(x) expr ))
> sapply(1:4, f({ a <- x^2 ; b <- x^3 ; a+b }))
[1] 2 12 36 80
but I'm not sure it would have worked well. The new syntax is of course also more flexible.by clircle on 12/5/2020, 6:43:40 PM
I think I'm going to appreciate the native pipes, it will likely improve the readability of my data.table chains.
by arthurcolle on 12/5/2020, 8:31:00 PM
This is awesome. Wonder if they picked up on that specific syntactic operator from Elixir or from another world.
by stewbrew on 12/5/2020, 7:25:23 PM
Well, afaik it isn't really a pipe but syntactic sugar. A pipe streams data from one output stream to an input stream. This rewrites the code as if the input were passed as an argument.
by r-w on 12/6/2020, 2:44:42 AM
Julia crew, where you at?
by f6v on 12/5/2020, 6:39:49 PM
Better late than never, but dplyr solved the pipe problem long time ago.
by tpoacher on 12/6/2020, 12:36:45 AM
nitpicking, but this is not a lambda. it's an anonymous function.
by Huntsecker on 12/5/2020, 7:08:39 PM
personally Im surprised R is still in active development when the main use case for people to use R (at least when I was using it) was for statistical analysis. Python with its libraries (a lot I believe ported from R) just does is nicer, and faster.
I'm sure some of us who are out of the loop might be wondering: what about the magrittr pipe operator (%>%) that we all know and love?
Luke Tierney explains the move from %>% to a native pipe |> here [1]. The native pipe aims to be more efficient as well as addresses issues with the magrittr pipe like complex stack traces.
Turns out the |> syntax is also used in Julia, Javascript and F#.
The lambda syntax (\(x) -> x + 1) is similar to Haskell's (\x -> x + 1).
[1] https://www.youtube.com/watch?v=X_eDHNVceCU&feature=youtu.be...