That backslash syntax is pretty funky, but then again all of R is a little funky. Very nice addition to the language though!
Borrowed from Haskell. (Which of course does not make it unfunky.) https://wiki.haskell.org/Anonymous_function
R adds native pipe and lambda syntax
131–140 of 150 posts
Re: R adds native pipe and lambda syntax
#132Question 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…
> Question by someone who is ignorant but interested in functional programming: what is the closest equivalent to these functions in Python? The equivalent to the function of the first is python’s lambda syntax, there's no simple syntax providing the same function as the pipe.
Re: R adds native pipe and lambda syntax
#133Earlier quoted context omitted.
As someone who is now bouncing back & forth between Python and R on a weekly basis, I've been surprised (after making fun of R sometimes) how much I miss the piping when I leave R for Python. Pandas seems so inflexible by comparison, so nitpicky for little gain. I've been surprised again and again how much dplyr supports near-effortless fluency and productivity. Never really thought I'd be writing that in a public fo…
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.
Also Wes probably got the idea for row indeces from R.
Re: R adds native pipe and lambda syntax
#134Earlier 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…
I made the switch years ago and there is lots that python does better. I really, really wish for a perfect port of dplyr and ggplot2. Those are what I truly miss, everything else I'm pretty happy with.
Re: R adds native pipe and lambda syntax
#135Earlier 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.
I have used Julia a bit and really enjoyed it. The only reason I do not use it for work is lack of libraries. I know I could 'be the change I want to see in the world' and contribute, but given the pace of things at work I cannot fit that in on the company dime at this time...
Re: R adds native pipe and lambda syntax
#136Earlier quoted context omitted.
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 disam…
cars %>% zlm(dist ~ speed)
(or now) cars |> zlm(dist ~ speed)
https://github.com/torfason/zfitRe: R adds native pipe and lambda syntax
#137Same principle in octave: https://github.com/tpapastylianou/chain-ops-octave
Re: R adds native pipe and lambda syntax
#138nitpicking, but this is not a lambda. it's an anonymous function.
Care to elaborate?
Whereas what is proposed here is simply syntactic sugar for creating an anonymous function; from the little that is said in the announcement there is no reason to think this syntax would provide any guarantees that state changes due to lexical scoping won't affect the function's output.
Re: R adds native pipe and lambda syntax
#139Earlier quoted context omitted.
I'm not sure what specific "functions" you're talking about, but Python generally encourages a procedural style of programming as opposed to functional. The rationale is that functional code can be really difficult to read if you aren't already familiar with the idioms and terminology, whereas it's pretty easy to mentally parse and understand a `for` loop. So in that sense, list comprehensions are about as far as Pyt…
Having read plenty of python numerical code, I'm not sure "easy to parse and understand" is what exactly comes to mind.
Re: R adds native pipe and lambda syntax
#140Earlier quoted context omitted.
> Question by someone who is ignorant but interested in functional programming: what is the closest equivalent to these functions in Python? The equivalent to the function of the first is python’s lambda syntax, there's no simple syntax providing the same function as the pipe.
A pipe merely "pipes" the output of one function as an input to another. For example, | in bash. In Python this can be done the trivial way (by composing) or by using decorators.