Re: [R] Pipe operator

2023-01-03 Thread Ivan Calandra
Maybe I missed it in the whole discussion, but since R 4.2.0 the base R pipe operator also has a placeholder '_' to specify where the result of the left-hand side should be used in the right-hand side (see https://stat.ethz.ch/pipermail/r-announce/2022/000683.html). So the only difference in

Re: [R] Pipe operator

2023-01-03 Thread Richard O'Keefe
This is both true and misleading. The shell pipe operation came from functional programming. In fact the shell pipe operation is NOT "flip apply", which is what |> is, but it is functional composition. That is out = let out = command cmd1 | cmd2 = \x.cmd2(cmd1(x)). Pragmatically, the Unix shell

Re: [R] Pipe operator

2023-01-03 Thread Milan Glacier
With 50 years of programming experience, just think about how useful pipe operator is in shell scripting. The output of previous call becomes the input of next call... Genious idea from our beloved unix conversion... On 01/03/23 16:48, Sorkin, John wrote: I am trying to understand the reason

Re: [R] Pipe operator

2023-01-03 Thread Richard O'Keefe
"Does saving of variables speed up processing" no "or save memory" no. The manual is quite explicit: > ?"|>" ... Currently, pipe operations are implemented as syntax transformations. So an expression written as 'x |> f(y)' is parsed as 'f(x, y)'. Strictly speaking, using |> *doesn't* save any

Re: [R] Pipe operator

2023-01-03 Thread avi.e.gross
Boris, There are MANY variations possible and yours does not seem that common or useful albeit perfectly useful. I am not talking about making it a one-liner, albeit I find the multi-line version more useful. The pipeline concept seems sort of atomic in the following sense. R allows several

Re: [R] Pipe operator

2023-01-03 Thread Richard O'Keefe
The simplest and best answer is "fashion". In FSharp, > (|>);; val it: ('a -> ('a -> 'b) -> 'b) The ability to turn f x y into y |> f x makes perfect sense in a programming language where Currying (representing a function of n arguments as a function of 1 argument that returns a function of n-1

Re: [R] Pipe operator

2023-01-03 Thread Sorkin, John
Jeff, Thank you for contributing important information to this thread. From: Jeff Newmiller Sent: Tuesday, January 3, 2023 2:07 PM To: r-help@r-project.org; Sorkin, John; Ebert,Timothy Aaron; 'R-help Mailing List' Subject: Re: [R] Pipe operator The

Re: [R] Pipe operator

2023-01-03 Thread Jeff Newmiller
> 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

Re: [R] Pipe operator

2023-01-03 Thread Uwe Ligges
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

Re: [R] Pipe operator

2023-01-03 Thread Ivan Calandra
Dear John, some more experienced users might give you a different and more helpful answer, but I was not really convinced by the pipe operator until I tried it out, for the same reasons as you. In my opinion, the pipe operator is there only to improve the readability of your code. Think

Re: [R] Pipe operator

2023-01-03 Thread Andrew Hart via R-help
Keep in mind that in thie example you're processing x and placing the result back in x (so x must already exist). You can write this a bit more cleanly using the -> variant of the assignment operator as follows: x |> cos() |> max(pi/4) |> round(3) -> x Hth, Andrew. On 3/01/2023 16:00,

Re: [R] Pipe operator

2023-01-03 Thread Rui Barradas
Às 19:14 de 03/01/2023, Rui Barradas escreveu: Às 17:35 de 03/01/2023, Greg Snow escreveu: To expand a little on Christopher's answer. The short answer is that having the different syntaxes can lead to more readable code (when used properly). Note that there are now 2 different (but somewhat

Re: [R] Pipe operator

2023-01-03 Thread Jeff Newmiller
Ick. Some people like x |> cos() |> max(pi/4) |> round(3) -> x but I much prefer x <- x |> cos() |> max(pi/4) |> round(3) On January 3, 2023 11:00:46 AM PST, Boris Steipe wrote: >Working off Avi's example - would: > > x |> cos() |> max(pi/4) |> round(3) |> assign("x", value = _) > >...be

Re: [R] Pipe operator

2023-01-03 Thread Rui Barradas
Às 17:35 de 03/01/2023, Greg Snow escreveu: To expand a little on Christopher's answer. The short answer is that having the different syntaxes can lead to more readable code (when used properly). Note that there are now 2 different (but somewhat similar) pipes available in R (there could be

Re: [R] Pipe operator

2023-01-03 Thread Jeff Newmiller
The other responses here have been very good, but I felt it necessary to point out that the concept of a pipe originated around when you started programming [1] (text based). It did take awhile for it to migrate into programming languages such as OCaml, but Powershell makes extensive use of

Re: [R] Pipe operator

2023-01-03 Thread Boris Steipe
Working off Avi's example - would: x |> cos() |> max(pi/4) |> round(3) |> assign("x", value = _) ...be even more intuitive to read? Or are there hidden problems with that? Cheers, Boris > On 2023-01-03, at 12:40, avi.e.gr...@gmail.com wrote: > > John, > > The topic has indeed been

Re: [R] Pipe operator

2023-01-03 Thread avi.e.gross
Tim, There are differences and this one can be huge. The other pipe operators let you pass the current object to a later argument instead of the first by using a period to represent where to put it. The new one has a harder albeit flexible method by creating an anonymous function. -Original

Re: [R] Pipe operator

2023-01-03 Thread avi.e.gross
John, The topic has indeed been discussed here endlessly but new people still stumble upon it. Until recently, the formal R language did not have a built-in pipe functionality. It was widely used through an assortment of packages and there are quite a few variations on the theme including

Re: [R] Pipe operator

2023-01-03 Thread Greg Snow
To expand a little on Christopher's answer. The short answer is that having the different syntaxes can lead to more readable code (when used properly). Note that there are now 2 different (but somewhat similar) pipes available in R (there could be more in some package(s) that I don't know about,

Re: [R] Pipe operator

2023-01-03 Thread Ebert,Timothy Aaron
Christopher Ryan sent this example c(1:10) %>% sqrt() %>% mean() %>% plot() I could code this as A <- c(1:10) B <- sqrt(A) C<- mean(B) plot(C) I can then clean up by removing variables that I have no further use for. rm(A, B, C) The %>% operator is from the magriter package. It can be installed

Re: [R] Pipe operator

2023-01-03 Thread Sorkin, John
Tim, Thank you for your reply. I did not know about the |> operator. Do both %>% and |> work in base R? You suggested that the pipe operator can produce code with fewer variables. May I ask you to send a short example in which the pipe operator saves variables. Does said saving of variables

Re: [R] Pipe operator

2023-01-03 Thread Ebert,Timothy Aaron
The pipe shortens code and results in fewer variables because you do not have to save intermediate steps. Once you get used to the idea it is useful. Note that there is also the |> pipe that is part of base R. As far as I know it does the same thing as %>%, or at my level of programing I have

Re: [R] [External Email] Pipe operator

2023-01-03 Thread Christopher Ryan via R-help
I think there are probably a number of purposes for (advantages to?) the pipe operator. One is that it can avoid nested operations: plot(mean(sqrt(c(1:10 ## this is my silly example code which can get difficult to read. This is arguably easier to read and understand: c(1:10) %>% sqrt()

[R] Pipe operator

2023-01-03 Thread Sorkin, John
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

Re: [R] Functional Programming Problem Using purr and R's data.table shift function

2023-01-03 Thread Dénes Tóth
Hi Michael, R returns the result of the last evaluated expression by default: ``` add_2 <- function(x) { x + 2L } ``` is the same as and preferred over ``` add_2_return <- function(x) { out <- x + 2L return(out) } ``` In the idiomatic use of R, one uses explicit `return` when one wants

Re: [R] Stepmax in Neuralnet

2023-01-03 Thread Gábor Malomsoki
thanks, i have not tried yet, because the memory of my computer is too small, and i have to wait for the result ca 1 day. Am Di., 3. Jan. 2023 um 11:21 Uhr schrieb Ivan Krylov : > On Mon, 2 Jan 2023 17:50:09 +0100 > Gábor Malomsoki wrote: > > > if i set the stepmax parameter higher then i

Re: [R] Stepmax in Neuralnet

2023-01-03 Thread Ivan Krylov
On Mon, 2 Jan 2023 17:50:09 +0100 Gábor Malomsoki wrote: > if i set the stepmax parameter higher then i increase the performance > of the neuralnet? > Would be my prediction more accurate? Unfortunately, it's very hard to give a good answer to this question as stated. If the model is