Live data from Hacker News

R adds native pipe and lambda syntax

developer.r-project.org

31–40 of 150 posts

Re: R adds native pipe and lambda syntax

#31

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

Isn't the reason that magrittr was able to use that syntax that it already existed, so your proposal is a breaking change?

I thought %% was some sort of macro expansions and that is how magrittr creates pipes. But browsing through the magrittr github repo, it looks like they just define %>% and the other pipes as functions [1].

I don't actually know the relation between magrittr and the RStudio shortcut, but I've always assumed a shortcut for typing the pipe characters exist because RStudio employs Hadley Wichkham, who in turn is really big on tidyverse and pipes.

Would %>% mean anything in R if you didn't import magrittr?

[1] https://github.com/tidyverse/magrittr/blob/8b3d510f2a333b224...

Re: R adds native pipe and lambda syntax

#32

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

Pandas is used in some top 10 banks for analytics. Its performance is abysmal at the scale used there. Nobody wants to invest resources in training analysts to write high performance code so here we are. I have never viewed SQL more highly after seeing the mess that analysts make when writing imperative code.

Re: R adds native pipe and lambda syntax

#33

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

I use Python at work, but R is the uber weapon.

Re: R adds native pipe and lambda syntax

#34

Earlier quoted context omitted.

Isn't the reason that magrittr was able to use that syntax that it already existed, so your proposal is a breaking change?

I thought %% was some sort of macro expansions and that is how magrittr creates pipes. But browsing through the magrittr github repo, it looks like they just define %>% and the other pipes as functions [1]. I don't actually know the relation between magrittr and the RStudio shortcut, but I've always assumed a shortcut for typing the pipe characters exist because RStudio employs Hadley Wichkham, who in turn is really…

All %fun% constructs are just simple functions that can be created by the user and can be used as infix operators. Base R has a few of those: %in%, %o%, %*%, %x%, %%, %/%.

magrittr created %>% which, when used in infix: x %>% f() calls the function on the right side with the argument on the left side f(x).

There are package that provide tons more. For example: https://github.com/moodymudskipper/inops . And you can easily create your own:

    `%sum%` 

Re: R adds native pipe and lambda syntax

#35

Earlier quoted context omitted.

Isn't the reason that magrittr was able to use that syntax that it already existed, so your proposal is a breaking change?

I thought %% was some sort of macro expansions and that is how magrittr creates pipes. But browsing through the magrittr github repo, it looks like they just define %>% and the other pipes as functions [1]. I don't actually know the relation between magrittr and the RStudio shortcut, but I've always assumed a shortcut for typing the pipe characters exist because RStudio employs Hadley Wichkham, who in turn is really…

To define a new binary operator in R (which are just functions), it must be between % characters.

%>% does not mean anything in base R.

Re: R adds native pipe and lambda syntax

#38
post #17

Earlier quoted context omitted.

I think that symbol is used as an approximation of "lambda" character (λ) on a standard US keyboard.

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 can be done with option-l on macOS if you `inoremap ¬ *l` https://apple.stackexchange.com/questions/230422/type-lambda...).

Re: R adds native pipe and lambda syntax

#39
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…

In Windows, WinCompose lets you set up compose keys like that, although the default ⋄yy goes to ʎ.

Re: R adds native pipe and lambda syntax

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

Post reply on HN