John Mount explains a quirk in dplyr’s mutate function:
It is hard for experts to understand how frustrating the above is to a new
Ruser or to a part time
Ruser. It feels like any variation on the original code causes it to fail. None of the rules they have been taught anticipate this, or tell them how to get out of this situation.
This quickly leads to strong feelings of learned helplessness and anxiety.
Our rule for
dplyr::mutate()has been for some time:
Each column name used in a single mutate must appear only on the left-hand-side of a single assignment, or otherwise on the right-hand-side of any number of assignments (but never both sides, even if it is different assignments).
If you do data analysis with R, you’ve probably run into this before. I certainly have, and it’s nice to understand why this is the case.