2 ms·
tidyverse packages in R do this. Normally, you might have something like this: df = someFunctionThatReturnsADataFrame() newDf = someFunctionThatTakesAn
by nonameiguess 6y ago
tidyverse packages in R do this. Normally, you might have something like this:
df = someFunctionThatReturnsADataFrame()
newDf = someFunctionThatTakesAndReturnsADataFrame(df)
doSomethingTo(df)
Since R lets you define your own operators, they took '%>%' and defined it as "pipe the return value from one function as the first argument to another function," so you can do this:
someFunctionThatReturnsADataFrame() %>%
someFunctionThatTakesAndReturnsADataFrame() %>%
doSomethingTo()
No need to name either the temporaries or the function arguments.
- oivaksef 6y agoIRB the interactive ruby shell has _ which references the return value of the last command. So 10 + 10 puts _ # prints 20 but that isn't available in ruby itself