| Line 1... |
Line 1... |
| 1 |
% File src/library/base/man/pipeOp.Rd
|
1 |
% File src/library/base/man/pipeOp.Rd
|
| 2 |
% Part of the R package, https://www.R-project.org
|
2 |
% Part of the R package, https://www.R-project.org
|
| 3 |
% Copyright 1995-2022 R Core Team
|
3 |
% Copyright 1995-2024 R Core Team
|
| 4 |
% Distributed under GPL 2 or later
|
4 |
% Distributed under GPL 2 or later
|
| 5 |
|
5 |
|
| 6 |
\name{pipeOp}
|
6 |
\name{pipeOp}
|
| 7 |
\alias{|>}
|
7 |
\alias{|>}
|
| 8 |
\alias{pipeOp}
|
8 |
\alias{pipeOp}
|
| Line 16... |
Line 16... |
| 16 |
\arguments{
|
16 |
\arguments{
|
| 17 |
\item{lhs}{expression producing a value.}
|
17 |
\item{lhs}{expression producing a value.}
|
| 18 |
\item{rhs}{a call expression.}% or an expression of the form \code{symbol => call}
|
18 |
\item{rhs}{a call expression.}% or an expression of the form \code{symbol => call}
|
| 19 |
}
|
19 |
}
|
| 20 |
\details{
|
20 |
\details{
|
| 21 |
A pipe expression passes, or pipes, the result of the left-hand side
|
21 |
A pipe expression passes, or \sQuote{pipes}, the result of the left-hand-side
|
| 22 |
expression \code{lhs} to the right-hand side expression \code{rhs}.
|
22 |
expression \code{lhs} to the right-hand-side expression \code{rhs}.
|
| 23 |
|
23 |
|
| 24 |
The \code{lhs} is
|
24 |
The \code{lhs} is
|
| 25 |
inserted as the first argument in the call. So \code{x |> f(y)} is
|
25 |
inserted as the first argument in the call. So \code{x |> f(y)} is
|
| 26 |
interpreted as \code{f(x, y)}.
|
26 |
interpreted as \code{f(x, y)}.
|
| 27 |
|
27 |
|
| Line 41... |
Line 41... |
| 41 |
Pipe notation allows a nested sequence of calls to be written in a way
|
41 |
Pipe notation allows a nested sequence of calls to be written in a way
|
| 42 |
that may make the sequence of processing steps easier to follow.
|
42 |
that may make the sequence of processing steps easier to follow.
|
| 43 |
|
43 |
|
| 44 |
Currently, pipe operations are implemented as syntax transformations.
|
44 |
Currently, pipe operations are implemented as syntax transformations.
|
| 45 |
So an expression written as \code{x |> f(y)} is parsed as \code{f(x,
|
45 |
So an expression written as \code{x |> f(y)} is parsed as \code{f(x,
|
| 46 |
y)}. It is worth emphasizing that while the code in a pipeline is
|
46 |
y)}. It is worth emphasizing that while the code in a pipeline is
|
| 47 |
written sequentially, regular R semantics for evaluation apply and
|
47 |
written sequentially, regular R semantics for evaluation apply and
|
| 48 |
so piped expressions will be evaluated only when first used in the
|
48 |
so piped expressions will be evaluated only when first used in the
|
| 49 |
\code{rhs} expression.
|
49 |
\code{rhs} expression.
|
| 50 |
}
|
50 |
}
|
| 51 |
\value{
|
51 |
\value{
|
| 52 |
Returns the result of evaluating the transformed expression.
|
52 |
Returns the result of evaluating the transformed expression.
|
| 53 |
}
|
53 |
}
|
| 54 |
\section{Background}{
|
54 |
\section{Background}{
|
| 55 |
The forward pipe operator is motivated by the pipe introduced in the
|
55 |
The forward pipe operator is motivated by the pipe introduced in the
|
| 56 |
\CRANpkg{magrittr} package, but is more streamlined. It is similar to
|
56 |
\CRANpkg{magrittr} package, but is more streamlined. It is similar to
|
| 57 |
the pipe or pipeline operators introduced in other languages, including
|
57 |
the pipe or pipeline operators introduced in other languages, including
|
| 58 |
F#, Julia, and JavaScript.
|
58 |
F#, Julia, and JavaScript.
|
| 59 |
}
|
59 |
}
|
| - |
|
60 |
\section{Warning}{
|
| - |
|
61 |
This was introduced in \R 4.1.0. Code using it will not be parsed
|
| - |
|
62 |
as intended (probably with an error) in earlier versions of \R.
|
| - |
|
63 |
}
|
| 60 |
\examples{
|
64 |
\examples{
|
| 61 |
# simple uses:
|
65 |
# simple uses:
|
| 62 |
mtcars |> head() # same as head(mtcars)
|
66 |
mtcars |> head() # same as head(mtcars)
|
| 63 |
mtcars |> head(2) # same as head(mtcars, 2)
|
67 |
mtcars |> head(2) # same as head(mtcars, 2)
|
| 64 |
mtcars |> subset(cyl == 4) |> nrow() # same as nrow(subset(mtcars, cyl == 4))
|
68 |
mtcars |> subset(cyl == 4) |> nrow() # same as nrow(subset(mtcars, cyl == 4))
|