Skip to content

Commit

Permalink
style
Browse files Browse the repository at this point in the history
  • Loading branch information
ddsjoberg committed Jan 23, 2024
1 parent 8659a56 commit 0e8e72c
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 30 deletions.
35 changes: 19 additions & 16 deletions R/ard_proportion_ci.R
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,14 @@ ard_proportion_ci <- function(data, variables, by = dplyr::group_vars(data),
strata,
weights = NULL,
max.iterations = 10,
method = c("waldcc", "wald", "clopper-pearson",
"wilson", "wilsoncc",
"strat_wilson", "strat_wilsoncc",
"agresti-coull", "jeffreys")) {
method = c(
"waldcc", "wald", "clopper-pearson",
"wilson", "wilsoncc",
"strat_wilson", "strat_wilsoncc",
"agresti-coull", "jeffreys"
)) {
# process inputs -------------------------------------------------------------
cards::process_selectors(data, variables = {{ variables }}, by = {{ by }})
cards::process_selectors(data, variables = {{ variables }}, by = {{ by }})
method <- arg_match(method)
if (method %in% c("strat_wilson", "strat_wilsoncc")) {
cards::process_selectors(data, strata = strata)
Expand All @@ -47,10 +49,9 @@ ard_proportion_ci <- function(data, variables, by = dplyr::group_vars(data),
variables = {{ variables }},
by = {{ by }},
statistics =
~list(
~ list(
prop_ci =
switch(
method,
switch(method,

Check warning on line 54 in R/ard_proportion_ci.R

View workflow job for this annotation

GitHub Actions / SuperLinter 🦸‍♀️ / Lint R code 🧶

file=R/ard_proportion_ci.R,line=54,col=10,[indentation_linter] Indentation should be 8 spaces but is 10 spaces.
"waldcc" = \(x, ...) proportion_ci_wald(x, conf.level = conf.level, correct = TRUE),
"wald" = \(x, ...) proportion_ci_wald(x, conf.level = conf.level, correct = FALSE),
"wilsoncc" = \(x, ...) proportion_ci_wilson(x, conf.level = conf.level, correct = TRUE),
Expand All @@ -59,14 +60,18 @@ ard_proportion_ci <- function(data, variables, by = dplyr::group_vars(data),
"agresti-coull" = \(x, ...) proportion_ci_agresti_coull(x, conf.level = conf.level),
"jeffreys" = \(x, ...) proportion_ci_jeffreys(x, conf.level = conf.level),
"strat_wilsoncc" = \(x, data, ...) {
proportion_ci_strat_wilson(x, strata = data[[strata]], weights = weights,
max.iterations = max.iterations,
conf.level = conf.level, correct = TRUE)
proportion_ci_strat_wilson(x,
strata = data[[strata]], weights = weights,
max.iterations = max.iterations,
conf.level = conf.level, correct = TRUE
)
},
"strat_wilson" = \(x, data, ...) {
proportion_ci_strat_wilson(x, strata = data[[strata]], weights = weights,
max.iterations = max.iterations,
conf.level = conf.level, correct = FALSE)
proportion_ci_strat_wilson(x,
strata = data[[strata]], weights = weights,
max.iterations = max.iterations,
conf.level = conf.level, correct = FALSE
)
}
)
)
Expand All @@ -75,5 +80,3 @@ ard_proportion_ci <- function(data, variables, by = dplyr::group_vars(data),
context = "proportion_ci"
)
}


20 changes: 13 additions & 7 deletions R/standalone-checks.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
check_class <- function(x, class, allow_null = FALSE,
arg_name = rlang::caller_arg(x), call = parent.frame()) {
# include NULL class as acceptable if allow_null is TRUE
if (isTRUE(allow_null) && is.null(x)) return(invisible())
if (isTRUE(allow_null) && is.null(x)) {
return(invisible())
}

if (!inherits(x, class)) {
cli::cli_abort("The {.arg {arg_name}} argument must be class {.cls {class}}.", call = call)
Expand All @@ -35,8 +37,10 @@ check_class <- function(x, class, allow_null = FALSE,
#' @keywords internal
check_class_data_frame <- function(x, allow_null = FALSE,
arg_name = rlang::caller_arg(x), call = parent.frame()) {
check_class(x = x, class = "data.frame", allow_null = allow_null,
arg_name = arg_name, call = call)
check_class(
x = x, class = "data.frame", allow_null = allow_null,
arg_name = arg_name, call = call
)
}

#' Check Argument not Missing
Expand Down Expand Up @@ -93,7 +97,8 @@ check_range <- function(x,
msg = paste(
"The {.arg {arg_name}} argument must be in the interval",
"{.code {ifelse(include_bounds[1], '[', '(')}{range[1]},",
"{range[2]}{ifelse(include_bounds[2], ']', ')')}}."),
"{range[2]}{ifelse(include_bounds[2], ']', ')')}}."
),
call = parent.frame()) {
if (isTRUE(scalar)) {
check_scalar(x, arg_name = arg_name)
Expand Down Expand Up @@ -143,13 +148,14 @@ check_range <- function(x,
#' @keywords internal
check_binary <- function(x, arg_name = caller_arg(x), call = parent.frame()) {
if (!is.logical(x) && !(is_integerish(x) && is_empty(setdiff(x, c(0, 1, NA))))) {
paste("Expecting column {.arg {arg_name}} to be either {.cls logical}",
"or {.cls {c('numeric', 'integer')}} coded as {.val {c(0, 1)}}.") |>
paste(
"Expecting column {.arg {arg_name}} to be either {.cls logical}",
"or {.cls {c('numeric', 'integer')}} coded as {.val {c(0, 1)}}."
) |>
cli::cli_abort(call = call)
}

invisible()
}

# nocov end

9 changes: 6 additions & 3 deletions tests/spelling.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
if(requireNamespace('spelling', quietly = TRUE))
spelling::spell_check_test(vignettes = TRUE, error = FALSE,
skip_on_cran = TRUE)
if (requireNamespace("spelling", quietly = TRUE)) {
spelling::spell_check_test(
vignettes = TRUE, error = FALSE,
skip_on_cran = TRUE
)
}
10 changes: 6 additions & 4 deletions tests/testthat/test-ard_proportion_ci.R
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
test_that("ard_proportion_ci() works", {
# testing the easy methods together
expect_error(
c("waldcc", "wald", "clopper-pearson",
"wilson", "wilsoncc", "agresti-coull", "jeffreys") |>
c(
"waldcc", "wald", "clopper-pearson",
"wilson", "wilsoncc", "agresti-coull", "jeffreys"
) |>
lapply(
\(x) {
ard_proportion_ci(
Expand Down Expand Up @@ -40,7 +42,7 @@ test_that("ard_proportion_ci(method='strat_wilson') works", {
variables = rsp,
strata = strata,
weights = weights,
method = 'strat_wilson'
method = "strat_wilson"
)
)

Expand All @@ -53,7 +55,7 @@ test_that("ard_proportion_ci(method='strat_wilson') works", {
variables = rsp,
strata = strata,
weights = weights,
method = 'strat_wilsoncc'
method = "strat_wilsoncc"
)
)
})

0 comments on commit 0e8e72c

Please sign in to comment.