I'm working on a new package for creating and working with spatial interaction models (SIMs) in R. I'm testing out non-standard evaluation and have found that this function works well:
si_calculate = function(.data, fun, ...) {
dots = rlang::enquos(...)
od = dplyr::mutate(od, interaction = fun(!!!dots))
od
}
Works well, better than the previous implementation, in terms of allowing use in dplyr pipelines:
si_calculate = function(data, fun, ...) {
od$interaction = fun(od, ...)
od
}
The above are simplified versions of code in this PR: Tidyeval by Robinlovelace · Pull Request #10 · Robinlovelace/si · GitHub
See here for more context: https://twitter.com/robinlovelace/status/1517397049569943553
I've looked at the rlang docs for enquos()
and associated vignettes but can find little on best practice for this kind of thing and am wondering if this is a common/effective pattern in NSE? Thanks!