Live data from Hacker News

R adds native pipe and lambda syntax

developer.r-project.org

141–150 of 150 posts

Re: R adds native pipe and lambda syntax

#141

Earlier quoted context omitted.

Having read plenty of python numerical code, I'm not sure "easy to parse and understand" is what exactly comes to mind.

Most of the problem comes from Pandas which is of course R-inspired.

Yup, it's a terrible shame that pandas started off as a base-R clone in Python.

Now, the only time I write base-R like code is in Python, which is pretty weird.

It's also strange as sklearn is beautiful, and in general python libraries are nicer than the equivalents in R, but pandas is a large, warty exception.

Re: R adds native pipe and lambda syntax

#142
post #98

Earlier quoted context omitted.

I'm not an R user, but you should try Julia for data analysis. It seems as flexibility (maybe more) than R, while also having blazing performance. I do like Pandas concept of row indices, which I know Julia (and I believe, R) lack.

You should try using R; the real world performance is actually better than Julia in every way that matters. Yes, Julia has a better data frame object; that's why we use data.tables(). Also Wes probably got the idea for row indeces from R.

The idea for row indices 100% comes from R, as it's been in S for longer than I've been alive ;)

Re: R adds native pipe and lambda syntax

#143
post #64
post #47

Earlier quoted context omitted.

I'm sure they wanted to not replace magrittr pipes. R is introspective, and some reckless people (like myself) will mess with functions' guts in a few scripts. Replacing the `%>%` function with a syntax symbol will break those scripts. Even with scripts that don't metaphorically shove their hands down the garbage disposal, programmers might've relied on certain behaviors of the magrittr pipe. The R Core team is very…

It seems to have been worth the caution. R has a great reputation for stability. The contrast between my experiences in R and python datascience tools is stark. Pandas syntax has changed wildly since I started learning it, but R and tidyverse hasn’t really changed at all. Admittedly pandas was in rapid and early development at the time.

I think the R reputation for stability is entirely driven by CRAN. If your package doesn't build on the latest version of R, it is marked unavailable. This means that people can build on R-current, in a way that simply isn't possible with the state of python packaging.

Maybe Python just needs a bigger repository with more stringent rules for what will be allowed?

Re: R adds native pipe and lambda syntax

#144

Earlier quoted context omitted.

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 disam…

The zfit package is intended to address this issue, with the zlm() and comparable functions that are very thin wrappers around lm() and friends. The ony thing they do is flip the argument order so the data comes first, making exactly this use case much simpler. So you can do: cars %>% zlm(dist ~ speed) (or now) cars |> zlm(dist ~ speed) https://github.com/torfason/zfit

Tbh, I would 1000% rather my coworkers write a lambda function or closure where it's necessary than add a new package depencency just to change the order of arguments in widely used functions.

Plus, I still wouldn't trust the code

    cars %>% zlm(dist ~ .)
to necessarily work the way I want, or to work the same way across package versions.

Re: R adds native pipe and lambda syntax

#145

Earlier quoted context omitted.

A better solution is just to use the word 'lambda', and let your text editor render it as a lambda symbol if you want (my emacs does this).

No, that's a shithouse solution. Everyone that doesn't have a fancy IDE now has 6-8 extra useless characters for something that should be syntax.

How is it different than the word "function"?

Re: R adds native pipe and lambda syntax

#146

Earlier quoted context omitted.

No, that's a shithouse solution. Everyone that doesn't have a fancy IDE now has 6-8 extra useless characters for something that should be syntax.

How is it different than the word "function"?

It's not, that's why people use arrow syntax in languages like Javascript for short in-lined functions.

Re: R adds native pipe and lambda syntax

#147
post #83

Earlier quoted context omitted.

I use Python whenever I can, but R has loads and loads of statistical libraries that Pyrhon doesn’t. It is not even close.

What kind of stat problems? Also I used to love Python... Until I got a full time job and learned why static typing exists.

Any sort of statistical or econometric estimator is typically published as an R package.

So for example, I recently saw a paper with a quite complex estimator based on dynamic panels and network (or spacial) interdependence that could identify missing network ties. For that, an R package exists.

If you want to use it in Python, you'd have to replicate a whole estimation infrastructure yourself, starting by extending the basic models in statsmodels.

That example is quite typical in my opinion.

Like I said, really like to code in Python and I don't like R all that much. But if someone says: "Why would you use R, Python is better", then we can confidently say the person does not know what R is actually used for.

Re: R adds native pipe and lambda syntax

#148
post #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…

You might be interested in coconut [0] which extends python with functional concepts and compiles to python.

[0] http://coconut-lang.org/

Re: R adds native pipe and lambda syntax

#149
post #38

Earlier quoted context omitted.

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…

Now imagine doing that same thing for every system you're programming on. And then imagine having to do it for a million different symbols. I'm sure as hell glad you're not in charge of any of this.

> Now imagine doing that same thing for every system you're programming on.

As a matter of fact, I already do, the XCompose way.

  yadm clone /path/to/dotfiles/repo.git¹
As for the vim way, why would I use a system without vim²?

> And then imagine having to do it for a million different symbols.

I don’t know other symbols as useful as this, but sure, either of my solutions scales fine (`yadm clone` shouldn’t get bogged down by any repo smaller than the Linux kernel’s). My system's /usr/share/X11/locale/en_US.UTF-8/Compose already has a section for APL’s symbols out of the box.

¹yadm is dumb by the way, any symlink manager + git/hg is probably better

²As it so happens, I do: because vim is bloat and https://sr.ht/~martanne/vis/ fits much better in the ramdisk my OS always runs in — but I’d bet 99.99% ±0.009% of programmers install their OS on an HDD/SSD and don’t care.

Re: R adds native pipe and lambda syntax

#150
post #64

Earlier quoted context omitted.

It seems to have been worth the caution. R has a great reputation for stability. The contrast between my experiences in R and python datascience tools is stark. Pandas syntax has changed wildly since I started learning it, but R and tidyverse hasn’t really changed at all. Admittedly pandas was in rapid and early development at the time.

I think the R reputation for stability is entirely driven by CRAN. If your package doesn't build on the latest version of R, it is marked unavailable. This means that people can build on R-current, in a way that simply isn't possible with the state of python packaging. Maybe Python just needs a bigger repository with more stringent rules for what will be allowed?

CRAN is definitely one of the best "features" of R. A very strict and official repository that requires human approval. Most often, that human is part of or close to the R Core team. Most guides I've read for getting a package on CRAN have to mention not wasting the time of somebody who's likely a busy statistics professor.
Post reply on HN