-
Notifications
You must be signed in to change notification settings - Fork 303
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
Dangerous silent failures due to no argument matching #413
Comments
I think a simple solution would be to have a utility function that checks for common mistakes:
|
The big issue is when you have a function that takes Suppose you have some function check_dots <- function(...) {
# use match.call to avoid evaluating arguments in ...
passed <- names(as.list(match.call())[-1])
if (length(passed) > 0)
stop("Unused arguments: ", paste(passed, collapse = ", "))
}
# suppose this takes ... to align with a generic signature
g <- function(a, b, round_result = FALSE, ...) {
check_dots(...)
res <- a * b
if (round_result) round(res) else res
}
g(1, 2, some_misspelled_argument = 4) Often, though, you might pass g <- function(a, b, round_result = FALSE, ...) {
res <- a * b
if (round_result) round(res) else res
}
g(1, 2, some_misspelled_argument = 4) # succeeds This is especially worrisome in a modelling context. Imagine something like misspelling In f <- function(x = 3, y = 4, ...) {
res <- g(x, y, ...)
res
} and |
This turns out to be a much deeper problem than I had any clue about, but luckily the tidyverse crew has https://github.com/hadley/ellipsis. To use this package we just add an |
This issue has been automatically closed due to inactivity. |
This issue has been automatically locked. If you believe you have found a related problem, please file a new issue (with a reprex: https://reprex.tidyverse.org) and link to this issue. |
We should keep this open, but really the solution here is to use |
This comment was marked as off-topic.
This comment was marked as off-topic.
Some more recent thoughts on this:
:) |
One example: it can look like you're augmenting
newdata
:while you're just getting the augmented original data because
augment.Mclust
doesn't actually take anewdata
argument.validate_augment_input
is going to deal with this in theaugment
case but this is generally an issue with generics where you think you've passed an argument but it just gets absorbed in...
and ignored. In general some sort ofmatch.arg
should fix this. This is especially likely to happen in packages likebroom
that wrap lots of things and send stuff through preprocessing helpers likeaugment_columns
orprocess_lm
.There are probably a lot of places in
broom
where we need to check that this isn't happening.Argument matching would be a good thing to include a
Best practices for developing modelling packages
document. cc @topepoThe text was updated successfully, but these errors were encountered: