-
Notifications
You must be signed in to change notification settings - Fork 8
Consider dot-prefixing all parameter names in functions where we take in user-controlled named ...
#162
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
(<- expand for details) Partial matching only appears to be an issue for parameters we declare before the dots (`x`, `f`, and `n` in the slide functions). For parameters declared after the dots, only exact matches are a concern.dots_first = function(..., abcde=2) {
cat("abcde:\n")
print(abcde)
cat("list(...):\n")
print(list(...))
}
dots_last = function(abcde=2, ...) {
cat("abcde:\n")
print(abcde)
cat("list(...):\n")
print(list(...))
}
# `dots_first` avoids partial-match problems of `dots_last`:
dots_first(abc=10)
#> abcde:
#> [1] 2
#> list(...):
#> $abc # <------------- placed `abc` in dots, the more reasonable place
#> [1] 10
dots_last(abc=10)
#> abcde: # <------------- matched `abc` to `abcde` parameter, less reasonable
#> [1] 10
#> list(...):
#> list()
# but of course doesn't avoid (rarer) exact-match issues. Regardless of where
# `...` appears in the function signature, calling with `abcde=10` will match to
# an `abcde` parameter rather than placing `abcde=10` into `...`. If `abcde` is
# a popular column name or `f` parameter name (e.g., `n`), then these exact
# matches get in the way.
dots_first(abcde=10)
#> abcde:
#> [1] 10
#> list(...):
#> list()
dots_last(abcde=10)
#> abcde:
#> [1] 10
#> list(...):
#> list() Created on 2022-07-30 by the reprex package (v2.0.1) (then annotated) Since we keep most parameters to the right of The above is just for clarification; it still looks like prefixing parameter names with dots, especially the currently-single-character parameter names, could help reduce the frequency of name conflicts. (Although we might want to think about whether the user will want to use |
#161 sort of interacts with this: if |
...
...
note: |
Let's call this done in #477 and open a new issue if we want to cover more of the package. |
Arose from this discussion. When the user can specify desired output columns or arguments to their own functions in
...
, there is the danger ofpartial[see clarification below; this can be the source of problems, but not our current problems] argument name matching assigning args the user meant to be part of...
to one of our built-in parameters, and getting incorrect output or cryptic errors. Ryan has already encountered this once. The approach ofdplyr
andpurrr
is to put a dot prefix on all their built-in parameters, as users typically won't use dots as the first character in their own column or function parameter names. We should consider doing the same inepi_slide
,epix_slide
, and any other similar functions.The text was updated successfully, but these errors were encountered: