Live data from Hacker News

R adds native pipe and lambda syntax

developer.r-project.org

71–80 of 150 posts

Re: R adds native pipe and lambda syntax

#71

Earlier quoted context omitted.

No surprise there - pandas encourages ugly, inefficient code with its bloated, unintuitive API. Once I was a lead on a new project and asked the intern to write some basic ETL code for data in some spreadsheets. I said she could write it in Python if she wanted, because "Python is good for ETL", right? This intern was not dumb by any means, but she wrote code that took 5 minutes to do something that can be done in Al…

R’s meta programming facilities are head and shoulders above Python’s, which I think explains the brilliance of dplyr and dbplyr. But I feel like with R you have to scrape back a bunch of layers to get to the Schemey parts. I’ve always wondered what Hadley and Co would have done with dplyr and dbplyr had they had something like Racket at their disposal.

Unfortunately R success killed xlisp-stat: http://homepage.divms.uiowa.edu/~luke/xls/xlsinfo/

Edit: or maybe it's not dead? I just found http://www.user2019.fr/static/pres/t246174.pdf

Re: R adds native pipe and lambda syntax

#72
post #50

Earlier quoted context omitted.

IMO they should just bite the bullet and learn proper SQL. I say this as a data scientist who learned SQL later than C, Matlab, R, Python/Pandas (though earlier than PySpark).

I agree. SQL is nothing to be afraid of, and there's no happier place to be analyzing huge tabular datasets than in a modern columnar database

R’s data.table package is faster at these things out of the box than any single instance of a database server I’ve encountered. This is frustrating because I’m trying to explain some systemic issues we suffer by not using a relational database, but it’s really hard to make my case when data.table is one install.packages away and a version upgrade from Postgres 9 to something a little faster is gatekept by bureaucracy. I’ve been trying for months!

Re: R adds native pipe and lambda syntax

#73
post #69
post #6

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…

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.

Re: R adds native pipe and lambda syntax

#74
post #56

Earlier quoted context omitted.

I know R because that's what we used at my first company. I would love to switch to Python/Pandas but I'm comfortable with R and it does everything I need it to with one exception over ten years of heavy use. Python is wonderful but the cognitive load for switching in industry and academia without a clear cost benefit isn't worth it to most people I know in my shoes. I encourage new coders to learn Python but discoun…

R already has a better lambda than Python, simply by virtue of having first class functions. This is just a bit shorter notation for something that already existed.

[deleted]

Re: R adds native pipe and lambda syntax

#75

Earlier quoted context omitted.

I agree. SQL is nothing to be afraid of, and there's no happier place to be analyzing huge tabular datasets than in a modern columnar database

R’s data.table package is faster at these things out of the box than any single instance of a database server I’ve encountered. This is frustrating because I’m trying to explain some systemic issues we suffer by not using a relational database, but it’s really hard to make my case when data.table is one install.packages away and a version upgrade from Postgres 9 to something a little faster is gatekept by bureaucracy…

You need a columnar database for good performance. Try DuckDB to ease them into it, it's a columnar SQLite.

Re: R adds native pipe and lambda syntax

#76
post #6

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…

In the case anyone is curious about the origin of the (|>) pipeline symbol:

Although F# is its most well known early popularizer, it originated in Isabelle/ML, 1994, proposed by Tobias Nipkow.

Here is a blog post by Don Syme which embeds the email thread of its invention: https://web.archive.org/web/20190217164203/https://blogs.msd...

It's a fascinating look through time.

Of course, I should note this is the history for the pipe-forward operator for chaining (reverse) function application used in a programming language. The general concept is even earlier, as attested by the shell syntax for chaining anonymous pipes https://en.wikipedia.org/wiki/Pipeline_(Unix)#History.

Metanote: I was surprised I was unable to find an answer to who invented the (|>) pipe syntax through google. I could only find this Elm thread https://elixirforum.com/t/which-language-first-introduced-th... which got close but did not have the answer. I am therefore writing this here to hopefully surface it for future searches and "question answering AIs".

Re: R adds native pipe and lambda syntax

#77
post #40
post #6

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…

> 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 often uses the "y ~ x" formula notation, this might actually be picking up deficiencies in R's macro system rather than in the function notation and the problem got misdagnosed.

Re: R adds native pipe and lambda syntax

#78
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.

I think magrittr 2.0 has addressed that problem also.

Re: R adds native pipe and lambda syntax

#79
post #38
post #17

Earlier quoted context omitted.

It is, and it's not the first language to use it as such. But for many programmers it always triggers the 'escape' alarm in the mind, and it will always cause slight discomfort seeing it used in the raw.

IMO it should be like Fennel and just support `lambda` and `λ`. The latter is not even that hard to type, in virtually any free (libre) OS you can just $ echo ' : "Λ" # GREEK CAPITAL LETTER LAMDA : "λ" # GREEK CAPITAL LETTER LAMDA ' >> ~/.XCompose If you’re limited by a nonfree OS you should be able to patch the problem with free duct tape like Karabiner or AutoHotKey. And in vim you can just *l in insert mode (which…

I don’t think R yet has native Unicode support on every platform.

Re: R adds native pipe and lambda syntax

#80
post #76
post #6

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…

In the case anyone is curious about the origin of the (|>) pipeline symbol: Although F# is its most well known early popularizer, it originated in Isabelle/ML, 1994, proposed by Tobias Nipkow. Here is a blog post by Don Syme which embeds the email thread of its invention: https://web.archive.org/web/20190217164203/https://blogs.msd... It's a fascinating look through time. Of course, I should note this is the history…

Woah, I hadn't known that!

And given that I'm currently staring at Isabelle code most of the day for my Master's thesis at the chair of Prof. Nipkow, it's sightly surreal to learn about this here, heh.

Post reply on HN