[R] Pipe operator

Jeff Newmiller jdnewm|| @end|ng |rom dcn@d@v|@@c@@u@
Wed Jan 4 00:10:50 CET 2023


> R is a functional language, hence the pipe operator is not needed.

Not factual... just opinion. Please be conscious of your biases and preface opinion with a disclaimer.

I heard identical complaints from embedded assembly language programmers when C became all the rage... "don't need another way to say the same thing."

>Also it makes the code unreadable as it is less obvious how a call stack looks like and what the arguments to the function calls are.

How can it make the code unreadable if there is a 1:1 mapping between nested function calls and a pipe?

If _you_ don't like pipes, that is your opinion, but that statement is factually incorrect... both the parser equivalence and the popularity of the syntax prove you wrong. Many people find it more readable than nested prefix notation.

>It is relevant for a shell for piping text streams.

So you are willing to allow that it makes sense in shell script but not in R script? This is not a self-consistent position. The same expressive principles can apply in both shell and in R.

On January 3, 2023 2:32:17 PM PST, Uwe Ligges <ligges using statistik.tu-dortmund.de> wrote:
>R is a functional language, hence the pipe operator is not needed.
>Also it makes the code unreadable as it is less obvious how a call stack looks like and what the arguments to the function calls are.
>
>It is relevant for a shell for piping text streams.
>
>If people cannot live without the pipe operator (and I wonder why you want to add a level of complexity, as it is more obfuscated what the actual function calls are), please use R's internal one, as it is known by the parser and hence debugging etc is better integrated.
>
>Best,
>Uwe Ligges
>
>
>
>On 03.01.2023 17:48, Sorkin, John wrote:
>> I am trying to understand the reason for existence of the pipe operator, %>%, and when one should use it. It is my understanding that the operator sends the file to the left of the operator to the function immediately to the right of the operator:
>> 
>> c(1:10) %>% mean results in a value of 5.5 which is exactly the same as the result one obtains using the mean function directly, viz. mean(c(1:10)). What is the reason for having two syntactically different but semantically identical ways to call a function? Is one more efficient than the other? Does one use less memory than the other?
>> 
>> P.S. Please forgive what might seem to be a question with an obvious answer. I am a programmer dinosaur. I have been programming for more than 50 years. When I started programming in the 1960s the only pipe one spoke about was a bong.
>> 
>> John
>> 
>> ______________________________________________
>> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>
>______________________________________________
>R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
>https://stat.ethz.ch/mailman/listinfo/r-help
>PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>and provide commented, minimal, self-contained, reproducible code.

-- 
Sent from my phone. Please excuse my brevity.



More information about the R-help mailing list