This request (and the pull request I will subsequently make) is motivated by an issue @mikedecr brought to my attention. Unpacking the result of a pipe sequence with the %<-% operator from the zeallot package did not work as intended.
Here is a small example with a simple infix function, abstracting away zeallot::`%<-%`.
`%<<<%` <- `<-`
a %<<<% 3030 %>% as.character
#> [1] "3030"
a
#> [1] 3030
The expression prints out "3030" because the result of a %<<<% 3030 is passed to as.character. I propose to give the pipe operator precedence over infix functions.
`%<<<%` <- `<-`
b %<<<% 3030 %>% as.character
b
#> [1] "3030"
Thus, in the second example, %<<<% is passed b and the result of pipe sequence, 3030 %>% as.character. The result is what we would expect if we used <- instead of %<<<%.
Jumping back to zeallot, the new precedence would allow R users to compute values using pipe sequences and then unpack these values. My implementation, however, is generic, handling any infix function.
Implementation
I have implemented this on my fork of magrittr. In my implementation an infix function is treated like a pipe operator until the final assignment block of pipe(). In the assignment block, if an infix function is called, pipe() does not evaluate the LHS, this is left up to the infix function. Similar to how %<>% results in a call to <-, pipe() calls the infix function with the unevaluated LHS and the computed result of the pipe sequence.
Concerns
The helper function %||% is becoming increasingly popular. There may be instances where giving precedence to %>% interferes with usage of %||%.
I hope this issue does not unearth concerns laid to rest in #5.
Tests
I have added tests to cover my additions. Furthermore, all previous tests still pass.
Motivation & Proposal
This request (and the pull request I will subsequently make) is motivated by an issue @mikedecr brought to my attention. Unpacking the result of a pipe sequence with the
%<-%
operator from the zeallot package did not work as intended.Here is a small example with a simple infix function, abstracting away
zeallot::`%<-%`
.The expression prints out "3030" because the result of
a %<<<% 3030
is passed toas.character
. I propose to give the pipe operator precedence over infix functions.Thus, in the second example,
%<<<%
is passedb
and the result of pipe sequence,3030 %>% as.character
. The result is what we would expect if we used<-
instead of%<<<%
.Jumping back to zeallot, the new precedence would allow R users to compute values using pipe sequences and then unpack these values. My implementation, however, is generic, handling any infix function.
Implementation
I have implemented this on my fork of magrittr. In my implementation an infix function is treated like a pipe operator until the final assignment block of
pipe()
. In the assignment block, if an infix function is called,pipe()
does not evaluate the LHS, this is left up to the infix function. Similar to how%<>%
results in a call to<-
,pipe()
calls the infix function with the unevaluated LHS and the computed result of the pipe sequence.Concerns
The helper function
%||%
is becoming increasingly popular. There may be instances where giving precedence to%>%
interferes with usage of%||%
.I hope this issue does not unearth concerns laid to rest in #5.
Tests
I have added tests to cover my additions. Furthermore, all previous tests still pass.