Closed peterdesmet closed 6 years ago
The bug is that it works anywhere - it suggests something is wrong with the environment that magrittr is evaluating the code in.
It is because the pipes are not evaluated sequentially/individually for effeciency, but rather the pipeline is "compiled" and treated as one function. Each of the magrittr
pipes are technically the same, except for their name. Therefore, as long as the first pipe being evaluated (the last in the chain) is known in the calling environment, it will know what to do. This "problem" is not unique to %<>%
but applies to %T>%
and %$%
too.
I think this will be fixed as part of the simplified branch, we'll just need to make sure that function environment uses the calling environment of the pipe.
thanks for the great packages. this issue still exists.
Note: this was reported in July 2016 as a dplyr bug by @dkassler at https://github.com/tidyverse/dplyr/issues/2014. @hadley suggested to file it here as a magrittr bug. Could not find bug report (and I'm running into the same problem), so here it is.
When magrittr's compound assignment pipe-operator (%<>%) is used as part of a dplyr pipeline it works even if magrittr itself isn't attached.
But if the
%<>%
operator is the only operator in the pipeline and magrittr hasn't been attached, it results in an error:Note: same is true for loading
library(tidyverse)
without explicitly loadinglibrary(magrittr)
This is easy to resolve on the user end (by simply attaching magrittr in addition to dplyr), but can lead to some confusing behavior if you aren't expecting it. Might it make more sense to export
%<>%
from dplyr to avoid this inconsistency?