mutate_profile: dynamic column and expression upgrades #315
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
mutate_profile()
is a safe and efficient method for doing profile level calculations using expressions involving SPC columns to produce or modify site or horizon level columns. However, it can be difficult to "program" with because of the evaluation of...
where each argument becomes a new column. Sometimes the column names need to be calculated from data, and sometimes we want to reuse an expression on several columns.This PR is a proof of concept that adds
mutate_profile_raw()
which can be used if building sets of dynamic mutate expressions. Alsomutate_profile()
gainscol_names
argument for dynamic naming of columns.Also adds examples to the
mutate_profile()
docsThanks to @natearoe for discussion on this topic inspiring these upgrades.
I still need to think about the ergonomics.
Another possible approach would be to bring {rlang} dependency back in and use tidy data masking or tidy selection, allowing for use of verbs like
across()
orstarts_with()
to identify input variables. Even if that were to be implemented, there would still likely be value in having an approach likemutate_profile_raw()
Example: