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.
This PR adds the function
check_dots_named()
which ensures that dots are either empty (if.empty_ok = TRUE
) or all named dot parameter names are a valid subset of a function's parameter names.It is intended to combat a major downside of using
...
which is phrased as follows in chapter 6.6 of the book Advanced R:We can use
check_dots_named()
to address this second downside:It can also be used to build an
sapply()
function that fails "intelligently":The code to suggest valid argument names is largely borrowed from
rlang::arg_match()
.Internally I rely on the additional packages purrr, checkmate, utils and methods. Of course, checkmate could be ditched (at the cost of not doing argument checks) and
purrr::walk()
could be replaced byinvisible(lapply())
or a simplefor
-loop if desired. Just let me know whatever you prefer.Caveats regarding
check_dots_named()
:unnamed dots arguments are not checked (not the purpose of this function). Use
check_dots_used()
in addition tocheck_dots_named()
to ensure that all named arguments are valid and all unnamed arguments are consumed.It cannot properly check argument names of functions which only declare them in a "submethod" (or whatever this is called) like
base::seq()
.The following throws an error:
while providing
to
andby
unnamed is fine:If anyone knows how the parameter names of this type of functions could be determined, please let me know!
It doesn't allow named objects as input for unnamed
...
args, i.e. it might be a bit rash:Although I tried to, I'm not 100% sure if I got the terminology of arguments vs. parameters always right... 🤓🤪