Live data from Hacker News

R adds native pipe and lambda syntax

developer.r-project.org

81–90 of 150 posts

Re: R adds native pipe and lambda syntax

#81
post #77
post #40

Earlier quoted context omitted.

> The lambda syntax (\(x) -> x + 1) is similar to Haskell's (\x -> x + 1). The proposed lambda syntax for R is `\(x) x+1` so `\` will just be shorthand for `function`.

The anonymous function change is probably a (small) mistake. function(x) {x + 1} is already logically equivalent to and from some perspectives an arguable syntax improvement on \(x) x + 1 Giving everyone two ways of doing one thing just means the tutorials will be fragmented and beginners even more confused. Tierney mentioned that tidyverse found function(x) too verbose and uses fomula syntax. Given how tidyverse oft…

Having the option of writing

    \(x) x+1
instead of

    function(x) x+1
not only saves a few keystrokes.

It will also produce shorter, and clearer, lines of code.

What I don’t understand is the reference to “formula syntax”. What is the issue and how does the new syntax solve it?

Re: R adds native pipe and lambda syntax

#82

Earlier quoted context omitted.

R vs. Python flamewars always strike me as a Budweiser vs. Miller kind of argument. Neither is really a “craft beer” of programming languages. Neither are super remarkable as programming languages. Both made a bunch pragmatic tradeoffs to appeal to large audiences that share similar values—both are “average joe” beers. Python has comparative advantages over R in production roles. R has comparative advantage in statis…

Tidyverse absolutely has a hipster craft beer feel to it. I think it's great, but it's true.

There is nothing more hip than library(tidyverse) that I've found in python.

Re: R adds native pipe and lambda syntax

#83

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 use Python whenever I can, but R has loads and loads of statistical libraries that Pyrhon doesn’t. It is not even close.

Re: R adds native pipe and lambda syntax

#84

Earlier quoted context omitted.

Nah, it's not nicer. dplyr is way better than pandas. But there is no end to the supply of Python fanbois who only know Python and assume that whatever's in Python just has to be better

I don't mind pandas so much, although dplyr is quite nice IMO (feels like natural language and declarative/SQL like, whereas pandas ends up with lots of procedural idioms). ggplot is something that I don't think matplotlib is comparable to at all, though. I am so much faster at iterating on a visualization with R/ggplot than Python/matplotlib. Maybe it is my tooling, though. How about others who have used both? What…

ggplot >> matplotlib and dplyr >> pandas. its not even close imo.

Re: R adds native pipe and lambda syntax

#85
post #69

Earlier quoted context omitted.

Thanks, the video helped explain some things, along with this post from the R-devel list: https://stat.ethz.ch/pipermail/r-devel/2020-December/080173.... The reason for announcing the new lambda syntax at the same time seems to be to enable certain workflows that the magrittr pipe supports. The %>% operator, by default, pipes to the first argument of a function. If you want to pipe to a different argument, you can do…

The use of "." as an argument is actually probably one of my most common wtf's with pipes in general. I tend to use it a lot if I'm just piping a vector to base functions (gsub/grep have x as their third argument. This syntax looks like it makes that a little harder, but the new error messages are going to make everything so much better that I'm totally fine with it.

It is particularly infuriating in R, because

    lm(y ~ ., data = my_dataframe)
already means "regress the variable y on all other columns in `my_dataframe`." For big, interactive regresions, it's really natural to write

    my_original_dataframe %>%
        do_a_bunch_of_tranformations() %>%
        select(...) %>% # Pull out just the columns you want
        lm(y ~ ., data = .)
and god knows how that last line is going to be interpreted. So disambiguating through some mechanism is necessary anyway. A lambda is much better than some temporary variable that just holds the formula `y ~ .`.

Re: R adds native pipe and lambda syntax

#87

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 ( |> )

I'm pretty happy that they didn't, because silently replacing one operation with a similar operation that inevitably has different bugs and different ways of handling edge cases would be pretty frustrating. Letting both live side-by-side as people transition would be my preference.

Re: R adds native pipe and lambda syntax

#88

I wish more languages gave us a "|>" operator. Too many languages settle with dot notation, which confuses encapsulation/method calling with syntactical convenience.

This, along with inferior metaprogramming affordances, is the biggest reason pandas will never be as productive an analyst tool as R's dplyr. In R you can pipe anything into anything. In pandas you're stuck with the methods pandas gives you.

This is also why pandas API is so bloated. A lot of pandas special-case functionality, like dropping duplicate rows, can be replicated in R by chaining together more flexible and orthogonal primitives.

Re: R adds native pipe and lambda syntax

#89
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).

Re: R adds native pipe and lambda syntax

#90

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.

Nah, it's not nicer. dplyr is way better than pandas. But there is no end to the supply of Python fanbois who only know Python and assume that whatever's in Python just has to be better

yeah. Pick one, learn it, and you'll be fine, no patter if you chose Python or R.

Personally, I prefer R for my use case which is longitudinal analysis of experimental data.

Post reply on HN