Closed thisisnic closed 2 months ago
@ddsjoberg I was looking into this one, and some of it seems straightforward - I was looking at capturing the possible valid arguments to supply to the model fit function and comparing the supplied ones against that - but what about cases where the method allows users to pass in extra arguments to pass to other methods via ...
? This might make it more tricky to guarantee something is a misspelling.
# yay, unambiguous
names(formals(survival::Surv))
#> [1] "time" "time2" "event" "type" "origin"
# boo, ambiguous
names(formals(getS3method("t.test", "default")))
#> [1] "x" "y" "alternative" "mu" "paired"
#> [6] "var.equal" "conf.level" "..."
Created on 2024-06-27 with reprex v2.1.0
Or maybe it's not so ambiguous, as if we trace the docs all the way down, there are only so many possible values which can be passed in via ellipses and a lot of the time they're ignored? I'll admit being less familiar with the internals of stats functions in R.
those are good point @thisisnic ! 🤔🤔🤔
Perhaps something a little simpler where we just capture the error and return it with a bit more context?
# this is what the code currently looks like.
withr::with_namespace(
package = package,
call2(.fn = method, formula = formula, data = data, !!!method.args) |>
eval_tidy(env = env)
)
# maybe it could look something more like this?
call_to_run <- call2(.fn = method, formula = formula, data = data, !!!method.args)
withr::with_namespace(
package = package,
tryCatch(
eval_tidy(call_to_run, env = env),
error = function(e) {
cli::cli_abort(
c("There was an error evaluating model {.code {deparse1(call_to_run)}}. See error message below:",
x = conditionMessage(e))
)
}
)
)
BUT, there are some cases when deparse1(call_to_run)
is going to be U-G-L-Y!
.
? For example, call_to_run$data <- expr(.); deparse1(call_to_run)
.c("There was an error evaluating the model. See error message below:", x = conditionMessage(e))
Feature description
From a conversation I was having with @ddsjoberg:
Code of Conduct
Contribution Guidelines
Security Policy