Issue
We have:
> e1 <- quote(for (x in 42) x)
> str(e1)
language for (x in 42) x
but we piping does not work here:
> e2 <- for (x in 42) x |> quote()
> str(e2)
NULL
Troubleshooting
This is because:
> e2 <- for (x in 42) x |> quote()
is equivalent to:
> e2 <- for (x in 42) quote(x)
This might be what help("|>") refers to when it says:
To avoid ambiguities, functions in rhs calls may not be syntactically special, such as + or if.
Solution
The only way we can quote the full expression is if we wrap it in { ... } or ( ... ), e.g.
> e3 <- { for (x in 42) x } |> quote()
> str(e3)
language for (x in 42) x
- attr(*, "srcref")=List of 2
..$ : 'srcref' int [1:8] 1 7 1 7 7 7 1 1
.. ..- attr(*, "srcfile")=Classes 'srcfilecopy', 'srcfile' <environment: 0x6423c5c86a78>
..$ : 'srcref' int [1:8] 1 9 1 23 9 23 1 1
.. ..- attr(*, "srcfile")=Classes 'srcfilecopy', 'srcfile' <environment: 0x6423c5c86a78>
- attr(*, "srcfile")=Classes 'srcfilecopy', 'srcfile' <environment: 0x6423c5c86a78>
- attr(*, "wholeSrcref")= 'srcref' int [1:8] 1 0 1 25 0 25 1 1
..- attr(*, "srcfile")=Classes 'srcfilecopy', 'srcfile' <environment: 0x6423c5c86a78>
and
> e4 <- ( for (x in 42) x ) |> quote()
> str(e4)
language, mode "(": (for (x in 42) x)
Issue
We have:
but we piping does not work here:
Troubleshooting
This is because:
is equivalent to:
This might be what
help("|>")refers to when it says:Solution
The only way we can quote the full expression is if we wrap it in
{ ... }or( ... ), e.g.and