Skip to content

Commit a37c5e4

Browse files
Use more informative check_arg (#1031)
* Use more informative check_arg * fix * Update R/utils.R Co-authored-by: Brenton M. Wiernik <[email protected]> * replace with validate_argument * desc * lintr, styler --------- Co-authored-by: Brenton M. Wiernik <[email protected]>
1 parent 85b5f2d commit a37c5e4

File tree

9 files changed

+33
-28
lines changed

9 files changed

+33
-28
lines changed

DESCRIPTION

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,3 +223,4 @@ Config/testthat/edition: 3
223223
Config/testthat/parallel: true
224224
Config/Needs/website: easystats/easystatstemplate
225225
Config/rcmdcheck/ignore-inconsequential-notes: true
226+
Remotes: easystats/insight#938

R/2_ci.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ ci.glm <- function(x,
7373
vcov_args = NULL,
7474
verbose = TRUE,
7575
...) {
76-
method <- match.arg(method, choices = c("profile", "wald", "normal", "residual"))
76+
method <- insight::validate_argument(method, c("profile", "wald", "normal", "residual"))
7777

7878
# No robust vcov for profile method
7979
if (method == "profile") {

R/bootstrap_model.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ bootstrap_model.default <- function(model,
7575

7676
insight::check_if_installed("boot")
7777

78-
type <- match.arg(type, choices = c("ordinary", "parametric", "balanced", "permutation", "antithetic"))
78+
type <- insight::validate_argument(type, c("ordinary", "parametric", "balanced", "permutation", "antithetic"))
7979
parallel <- match.arg(parallel)
8080

8181
model_data <- data <- insight::get_data(model, verbose = FALSE) # nolint
@@ -156,7 +156,7 @@ bootstrap_model.merMod <- function(model,
156156
...) {
157157
insight::check_if_installed("lme4")
158158

159-
type <- match.arg(type, choices = c("parametric", "semiparametric"))
159+
type <- insight::validate_argument(type, c("parametric", "semiparametric"))
160160
parallel <- match.arg(parallel)
161161

162162
boot_function <- function(model) {
@@ -228,7 +228,7 @@ bootstrap_model.nestedLogit <- function(model,
228228
...) {
229229
insight::check_if_installed("boot")
230230

231-
type <- match.arg(type, choices = c("ordinary", "balanced", "permutation", "antithetic"))
231+
type <- insight::validate_argument(type, c("ordinary", "balanced", "permutation", "antithetic"))
232232
parallel <- match.arg(parallel)
233233

234234
model_data <- data <- insight::get_data(model, verbose = FALSE) # nolint

R/ci_generic.R

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,14 @@
1717
if (is.null(method)) {
1818
method <- "wald"
1919
}
20-
method <- match.arg(tolower(method), choices = c(
21-
"wald", "ml1", "betwithin", "kr",
22-
"satterthwaite", "kenward", "boot",
23-
"profile", "residual", "normal"
24-
))
20+
method <- tolower(method)
21+
method <- insight::validate_argument(
22+
method,
23+
c(
24+
"wald", "ml1", "betwithin", "kr", "satterthwaite", "kenward", "boot",
25+
"profile", "residual", "normal"
26+
)
27+
)
2528

2629
effects <- match.arg(effects)
2730
component <- match.arg(component)

R/extract_random_variances.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828

2929
# check for errors
3030
if (is.null(out) && isTRUE(verbose)) {
31-
insight::format_warning("Something went wrong when calculating random effects parameters. Only showing model's fixed effects now. You may use `effects=\"fixed\"` to speed up the call to `model_parameters()`.")
31+
insight::format_warning("Something went wrong when calculating random effects parameters. Only showing model's fixed effects now. You may use `effects=\"fixed\"` to speed up the call to `model_parameters()`.") # nolint
3232
}
3333

3434
out
@@ -45,7 +45,7 @@
4545
ci_random = NULL,
4646
verbose = FALSE,
4747
...) {
48-
component <- match.arg(component, choices = c("all", "conditional", "zero_inflated", "zi", "dispersion"))
48+
component <- insight::validate_argument(component, c("all", "conditional", "zero_inflated", "zi", "dispersion"))
4949

5050
out <- suppressWarnings(
5151
.extract_random_variances_helper(
@@ -208,7 +208,7 @@
208208
)
209209

210210
# fix names for uncorrelated slope-intercepts
211-
pattern <- paste0("(", paste0(insight::find_random(model, flatten = TRUE), collapse = "|"), ")\\.\\d+$")
211+
pattern <- paste0("(", paste(insight::find_random(model, flatten = TRUE), collapse = "|"), ")\\.\\d+$")
212212
out$Group <- gsub(pattern, "\\1", out$Group)
213213

214214
# remove non-used columns

R/methods_glmmTMB.R

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ model_parameters.glmmTMB <- function(model,
4747
ci_method <- .check_df_method(ci_method)
4848

4949
# which components to return?
50-
effects <- match.arg(effects, choices = c("fixed", "random", "all"))
51-
component <- match.arg(component, choices = c("all", "conditional", "zi", "zero_inflated", "dispersion"))
50+
effects <- insight::validate_argument(effects, c("fixed", "random", "all"))
51+
component <- insight::validate_argument(component, c("all", "conditional", "zi", "zero_inflated", "dispersion"))
5252

5353
# standardize only works for fixed effects...
5454
if (!is.null(standardize) && standardize != "refit") {
@@ -268,8 +268,8 @@ ci.glmmTMB <- function(x,
268268
verbose = TRUE,
269269
...) {
270270
method <- tolower(method)
271-
method <- match.arg(method, choices = c("wald", "normal", "ml1", "betwithin", "profile", "uniroot", "robust"))
272-
component <- match.arg(component, choices = c("all", "conditional", "zi", "zero_inflated", "dispersion"))
271+
method <- insight::validate_argument(method, c("wald", "normal", "ml1", "betwithin", "profile", "uniroot", "robust"))
272+
component <- insight::validate_argument(component, c("all", "conditional", "zi", "zero_inflated", "dispersion"))
273273

274274
if (is.null(.check_component(x, component, verbose = verbose))) {
275275
return(NULL)
@@ -315,8 +315,8 @@ standard_error.glmmTMB <- function(model,
315315
component = "all",
316316
verbose = TRUE,
317317
...) {
318-
component <- match.arg(component, choices = c("all", "conditional", "zi", "zero_inflated", "dispersion"))
319-
effects <- match.arg(effects, choices = c("fixed", "random"))
318+
component <- insight::validate_argument(component, c("all", "conditional", "zi", "zero_inflated", "dispersion"))
319+
effects <- insight::validate_argument(effects, c("fixed", "random"))
320320

321321
dot_args <- .check_dots(
322322
dots = list(...),
@@ -374,10 +374,10 @@ standard_error.glmmTMB <- function(model,
374374
#' @export
375375
simulate_model.glmmTMB <- function(model,
376376
iterations = 1000,
377-
component = c("all", "conditional", "zi", "zero_inflated", "dispersion"),
377+
component = "all",
378378
verbose = FALSE,
379379
...) {
380-
component <- match.arg(component)
380+
component <- insight::validate_argument(component, c("all", "conditional", "zi", "zero_inflated", "dispersion"))
381381
info <- insight::model_info(model, verbose = FALSE)
382382

383383
## TODO remove is.list() when insight 0.8.3 on CRAN

R/methods_lme4.R

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -193,22 +193,22 @@ model_parameters.merMod <- function(model,
193193
ci_method <- tolower(ci_method)
194194

195195
if (isTRUE(bootstrap)) {
196-
ci_method <- match.arg(
196+
ci_method <- insight::validate_argument(
197197
ci_method,
198-
choices = c("hdi", "quantile", "ci", "eti", "si", "bci", "bcai")
198+
c("hdi", "quantile", "ci", "eti", "si", "bci", "bcai")
199199
)
200200
} else {
201-
ci_method <- match.arg(
201+
ci_method <- insight::validate_argument(
202202
ci_method,
203-
choices = c(
203+
c(
204204
"wald", "normal", "residual", "ml1", "betwithin", "satterthwaite",
205205
"kenward", "kr", "boot", "profile", "uniroot"
206206
)
207207
)
208208
}
209209

210210
# which component to return?
211-
effects <- match.arg(effects, choices = c("fixed", "random", "all"))
211+
effects <- insight::validate_argument(effects, c("fixed", "random", "all"))
212212
params <- params_random <- params_variance <- NULL
213213

214214
# post hoc standardize only works for fixed effects...
@@ -343,7 +343,7 @@ ci.merMod <- function(x,
343343
iterations = 500,
344344
...) {
345345
method <- tolower(method)
346-
method <- match.arg(method, choices = c(
346+
method <- insight::validate_argument(method, c(
347347
"wald", "ml1", "betwithin", "kr",
348348
"satterthwaite", "kenward", "boot",
349349
"profile", "residual", "normal"
@@ -379,7 +379,7 @@ standard_error.merMod <- function(model,
379379
vcov_args = NULL,
380380
...) {
381381
dots <- list(...)
382-
effects <- match.arg(effects, choices = c("fixed", "random"))
382+
effects <- insight::validate_argument(effects, c("fixed", "random"))
383383

384384
if (effects == "random") {
385385
out <- .standard_errors_random(model)

R/utils.R

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@
220220
ifnotfound
221221
}
222222

223+
223224
.deprecated_warning <- function(old, new, verbose = TRUE) {
224225
if (verbose) {
225226
insight::format_warning(paste0(

man/simulate_model.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)