diff --git a/.github/workflows/R-CMD-check.yaml b/.github/workflows/R-CMD-check.yaml index 9f9b10800..50de31520 100644 --- a/.github/workflows/R-CMD-check.yaml +++ b/.github/workflows/R-CMD-check.yaml @@ -8,7 +8,6 @@ on: push: branches: [main, master] pull_request: - branches: [main, master] name: R-CMD-check diff --git a/.github/workflows/check.yaml b/.github/workflows/check.yaml index 7b65f4a1c..c35021adf 100644 --- a/.github/workflows/check.yaml +++ b/.github/workflows/check.yaml @@ -8,8 +8,6 @@ on: - synchronize - reopened - ready_for_review - branches: - - main push: branches: - main diff --git a/.github/workflows/test-coverage.yaml b/.github/workflows/test-coverage.yaml index 2c5bb5029..1ccc71c5f 100644 --- a/.github/workflows/test-coverage.yaml +++ b/.github/workflows/test-coverage.yaml @@ -4,7 +4,6 @@ on: push: branches: [main, master] pull_request: - branches: [main, master] name: test-coverage diff --git a/DESCRIPTION b/DESCRIPTION index acddf62c4..e65cd7db6 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -18,7 +18,7 @@ BugReports: https://github.com/insightsengineering/cardx/issues Depends: R (>= 4.1) Imports: - cards (>= 0.1.0.9002), + cards (>= 0.1.0.9014), cli (>= 3.6.1), dplyr (>= 1.1.2), glue (>= 1.6.2), diff --git a/NEWS.md b/NEWS.md index 1293440df..75971eab8 100644 --- a/NEWS.md +++ b/NEWS.md @@ -23,22 +23,25 @@ ard_moodtest() -> ard_stats_mood_test() - `ard_stats_anova()` for calculating ANOVA results using `stats::anova()`. (#12) - `ard_aod_wald_test()` for calculating Wald Tests for regression models using `aod::wald.test()`. (#84) - `ard_car_anova()` for calculating ANOVA results using `car::Anova()`. (#3) - - `ard_onewaytest()` for calculating ANOVA results using `stats::oneway.test()`. (#3) - - `ard_cohens_d()`, `ard_paired_cohens_d()`, `ard_hedges_g()`, and `ard_paired_hedges_g()` for standardized differences using `effectsize::cohens_d()` and `effectsize::hedges_g()`. (#50) - - `ard_proptest()` for tests of proportions using `stats::prop.test()`. (#64) + - `ard_stats_oneway_test()` for calculating ANOVA results using `stats::oneway.test()`. (#3) + - `ard_effectsize_cohens_d()`, `ard_effectsize_paired_cohens_d()`, `ard_effectsize_hedges_g()`, and `ard_effectsize_paired_hedges_g()` for standardized differences using `effectsize::cohens_d()` and `effectsize::hedges_g()`. (#50) + - `ard_stats_prop_test()` for tests of proportions using `stats::prop.test()`. (#64) - `ard_regression_basic()` for basic regression models. The function focuses on matching terms to underlying variables names. (#46) - - `ard_smd()` for calculating standardized mean differences using `smd::smd()`. (#4) - - `ard_survfit()` for survival analyses using `survival::survfit()`. (#43) - - `ard_svycontinuous()` for calculating univariate summary statistics from weighted/survey data using many functions from the {survey} package. (#68) - - `ard_svychisq()` for weighted/survey chi-squared test using `survey::svychisq()`. (#72) - - `ard_svyttest()` for weighted/survey t-tests using `survey::svyttest()`. (#70) - - `ard_svyranktest()` for weighted/survey rank tests using `survey::svyranktest()`. (#71) - - `ard_vif()` for calculating the variance inflation factor using `car::vif()`. (#10) + - `ard_smd_smd()` for calculating standardized mean differences using `smd::smd()`. (#4) + - `ard_survival_survfit()` for survival analyses using `survival::survfit()`. (#43) + - `ard_survey_svycontinuous()` for calculating univariate summary statistics from weighted/survey data using many functions from the {survey} package. (#68) + - `ard_survey_svychisq()` for weighted/survey chi-squared test using `survey::svychisq()`. (#72) + - `ard_survey_svyttest()` for weighted/survey t-tests using `survey::svyttest()`. (#70) + - `ard_survey_svyranktest()` for weighted/survey rank tests using `survey::svyranktest()`. (#71) + - `ard_car_vif()` for calculating the variance inflation factor using `car::vif()`. (#10) * Updated functions `ard_stats_t_test()`, `ard_stats_paired_t_test()`, `ard_stats_wilcox_test()`, `ard_stats_paired_wilcox_test()`, `ard_stats_chisq_test()`, `ard_stats_fisher_test()`, `ard_stats_kruskal_test()`, `ard_stats_mcnemar_test()`, and `ard_stats_mood_test()` to accept multiple variables at once. Independent tests are calculated for each variable. The `variable` argument is renamed to `variables`. (#77) * Updated `ard_stats_t_test()` and `ard_stats_wilcox_test()` to no longer require the `by` argument, which yields central estimates with their confidence intervals. (#82) +* Import cli call environment functions from `https://github.com/ddsjoberg/standalone/blob/main/R/standalone-cli_call_env.R` and implement `set_cli_abort_call` in user-facing functions. (#111, @edelarua) + + # cardx 0.1.0 * Initial release. diff --git a/R/ard_aod_wald_test.R b/R/ard_aod_wald_test.R index b575e11b1..6e068c82c 100644 --- a/R/ard_aod_wald_test.R +++ b/R/ard_aod_wald_test.R @@ -10,12 +10,13 @@ #' @return data frame #' @export #' -#' @examplesIf cards::is_pkg_installed(c("aod"), reference_pkg = "cardx") +#' @examplesIf do.call(asNamespace("cardx")$is_pkg_installed, list(pkg = "aod", reference_pkg = "cardx")) #' lm(AGE ~ ARM, data = cards::ADSL) |> #' ard_aod_wald_test() ard_aod_wald_test <- function(x, ...) { + set_cli_abort_call() # check installed packages --------------------------------------------------- - cards::check_pkg_installed("aod", reference_pkg = "cardx") + check_pkg_installed("aod", reference_pkg = "cardx") # check inputs --------------------------------------------------------------- check_not_missing(x) @@ -32,10 +33,12 @@ ard_aod_wald_test <- function(x, ...) { ) if (!is.null(reg_model[["error"]])) { - cli::cli_abort(c( - "Unable to identify underlying variable names in regression model.", - i = "Is this model type supported by {.fun broom.helpers::tidy_plus_plus}, which is the function used to identify variable names?" - )) + cli::cli_abort( + c("Unable to identify underlying variable names in regression model.", + i = "Is this model type supported by {.fun broom.helpers::tidy_plus_plus}, which is the function used to identify variable names?" + ), + call = get_cli_abort_call() + ) } aod <- reg_model[["result"]] %>% diff --git a/R/ard_car_anova.R b/R/ard_car_anova.R index 1c02fb524..2b4f91270 100644 --- a/R/ard_car_anova.R +++ b/R/ard_car_anova.R @@ -8,15 +8,17 @@ #' @return data frame #' @export #' -#' @examplesIf cards::is_pkg_installed(c("broom.helpers", "car"), reference_pkg = "cardx") +#' @examplesIf do.call(asNamespace("cardx")$is_pkg_installed, list(pkg = c("broom.helpers", "car"), reference_pkg = "cardx")) #' lm(AGE ~ ARM, data = cards::ADSL) |> #' ard_car_anova() #' #' glm(vs ~ factor(cyl) + factor(am), data = mtcars, family = binomial) |> #' ard_car_anova(test.statistic = "Wald") ard_car_anova <- function(x, ...) { + set_cli_abort_call() + # check installed packages --------------------------------------------------- - cards::check_pkg_installed(c("broom.helpers", "car"), reference_pkg = "cardx") + check_pkg_installed(pkg = c("broom.helpers", "car"), reference_pkg = "cardx") # check inputs --------------------------------------------------------------- check_not_missing(x) @@ -25,10 +27,13 @@ ard_car_anova <- function(x, ...) { car_anova <- cards::eval_capture_conditions(car::Anova(x, ...)) if (!is.null(car_anova[["error"]])) { - cli::cli_abort(c( - "There was an error running {.fun car::Anova}. See error message below.", - x = car_anova[["error"]] - )) + cli::cli_abort( + c( + "There was an error running {.fun car::Anova}. See error message below.", + x = car_anova[["error"]] + ), + call = get_cli_abort_call() + ) } car_anova[["result"]] |> diff --git a/R/ard_car_vif.R b/R/ard_car_vif.R index 66212247e..25397e9e5 100644 --- a/R/ard_car_vif.R +++ b/R/ard_car_vif.R @@ -14,10 +14,15 @@ #' @rdname ard_car_vif #' @export #' -#' @examples +#' @examplesIf do.call(asNamespace("cardx")$is_pkg_installed, list(pkg = "car", reference_pkg = "cardx")) #' lm(AGE ~ ARM + SEX, data = cards::ADSL) |> #' ard_car_vif() ard_car_vif <- function(x, ...) { + set_cli_abort_call() + + # check installed packages --------------------------------------------------- + check_pkg_installed("car", reference_pkg = "cardx") + # check inputs --------------------------------------------------------------- check_not_missing(x) @@ -30,7 +35,8 @@ ard_car_vif <- function(x, ...) { # we cannot get variable names, error out if (!is.null(lst_terms[["error"]])) { cli::cli_abort( - c("There was an error running {.fun car::vif}. See below.", x = vif[["error"]]) + c("There was an error running {.fun car::vif}. See below.", x = vif[["error"]]), + call = get_cli_abort_call() ) } vif$result <- dplyr::tibble( diff --git a/R/ard_effectsize_cohens_d.R b/R/ard_effectsize_cohens_d.R index ba6b45fd8..32c9f2f48 100644 --- a/R/ard_effectsize_cohens_d.R +++ b/R/ard_effectsize_cohens_d.R @@ -28,7 +28,7 @@ #' The data are then passed as #' `effectsize::cohens_d(x = data_wide[[]], y = data_wide[[]], paired = TRUE, ...)`. #' -#' @examplesIf cards::is_pkg_installed(c("effectsize", "parameters"), reference_pkg = "cardx") +#' @examplesIf do.call(asNamespace("cardx")$is_pkg_installed, list(pkg = c("effectsize", "parameters"), reference_pkg = "cardx")) #' cards::ADSL |> #' dplyr::filter(ARM %in% c("Placebo", "Xanomeline High Dose")) |> #' ard_effectsize_cohens_d(by = ARM, variables = AGE) @@ -47,8 +47,10 @@ NULL #' @rdname ard_effectsize_cohens_d #' @export ard_effectsize_cohens_d <- function(data, by, variables, ...) { + set_cli_abort_call() + # check installed packages --------------------------------------------------- - cards::check_pkg_installed(c("effectsize", "parameters"), reference_pkg = "cardx") + check_pkg_installed(c("effectsize", "parameters"), reference_pkg = "cardx") # check/process inputs ------------------------------------------------------- check_not_missing(data) @@ -88,9 +90,11 @@ ard_effectsize_cohens_d <- function(data, by, variables, ...) { #' @rdname ard_effectsize_cohens_d #' @export ard_effectsize_paired_cohens_d <- function(data, by, variables, id, ...) { + set_cli_abort_call() + # check installed packages --------------------------------------------------- - cards::check_pkg_installed("effectsize", reference_pkg = "cardx") - cards::check_pkg_installed("parameters", reference_pkg = "cardx") + check_pkg_installed(c("effectsize", "parameters"), reference_pkg = "cardx") + # check/process inputs ------------------------------------------------------- check_not_missing(data) check_not_missing(variables) diff --git a/R/ard_effectsize_hedges_g.R b/R/ard_effectsize_hedges_g.R index 4a4cd1bc0..aa849de88 100644 --- a/R/ard_effectsize_hedges_g.R +++ b/R/ard_effectsize_hedges_g.R @@ -28,7 +28,7 @@ #' The data are then passed as #' `effectsize::hedges_g(x = data_wide[[]], y = data_wide[[]], paired = TRUE, ...)`. #' -#' @examplesIf cards::is_pkg_installed(c("effectsize", "parameters", "withr"), reference_pkg = "cardx") +#' @examplesIf do.call(asNamespace("cardx")$is_pkg_installed, list(pkg = c("effectsize", "parameters", "withr"), reference_pkg = "cardx")) #' cards::ADSL |> #' dplyr::filter(ARM %in% c("Placebo", "Xanomeline High Dose")) |> #' ard_effectsize_hedges_g(by = ARM, variables = AGE) @@ -47,8 +47,10 @@ NULL #' @rdname ard_effectsize_hedges_g #' @export ard_effectsize_hedges_g <- function(data, by, variables, ...) { + set_cli_abort_call() + # check installed packages --------------------------------------------------- - cards::check_pkg_installed(c("effectsize", "parameters", "withr"), reference_pkg = "cardx") + check_pkg_installed(c("effectsize", "parameters", "withr"), reference_pkg = "cardx") # check/process inputs ------------------------------------------------------- check_not_missing(data) @@ -92,9 +94,10 @@ ard_effectsize_hedges_g <- function(data, by, variables, ...) { #' @rdname ard_effectsize_hedges_g #' @export ard_effectsize_paired_hedges_g <- function(data, by, variables, id, ...) { + set_cli_abort_call() + # check installed packages --------------------------------------------------- - cards::check_pkg_installed("effectsize", reference_pkg = "cardx") - cards::check_pkg_installed("parameters", reference_pkg = "cardx") + check_pkg_installed(c("effectsize", "parameters"), reference_pkg = "cardx") # check/process inputs ------------------------------------------------------- check_not_missing(data) diff --git a/R/ard_proportion_ci.R b/R/ard_proportion_ci.R index d7d08d1a4..dad57e5ee 100644 --- a/R/ard_proportion_ci.R +++ b/R/ard_proportion_ci.R @@ -22,7 +22,7 @@ #' @return an ARD data frame #' @export #' -#' @examplesIf cards::is_pkg_installed("broom", reference_pkg = "cardx") +#' @examplesIf do.call(asNamespace("cardx")$is_pkg_installed, list(pkg = "broom", reference_pkg = "cardx")) #' ard_proportion_ci(mtcars, variables = c(vs, am), method = "wilson") ard_proportion_ci <- function(data, variables, by = dplyr::group_vars(data), conf.level = 0.95, @@ -35,6 +35,11 @@ ard_proportion_ci <- function(data, variables, by = dplyr::group_vars(data), "strat_wilson", "strat_wilsoncc", "agresti-coull", "jeffreys" )) { + set_cli_abort_call() + + # check installed packages --------------------------------------------------- + check_pkg_installed(pkg = "broom", reference_pkg = "cardx") + # process inputs ------------------------------------------------------------- cards::process_selectors(data, variables = {{ variables }}, by = {{ by }}) method <- arg_match(method) diff --git a/R/ard_regression.R b/R/ard_regression.R index 974787778..a7b0561cb 100644 --- a/R/ard_regression.R +++ b/R/ard_regression.R @@ -11,7 +11,7 @@ #' @return data frame #' @name ard_regression #' -#' @examplesIf cards::is_pkg_installed("broom.helpers", reference_pkg = "cardx") +#' @examplesIf do.call(asNamespace("cardx")$is_pkg_installed, list(pkg = "broom.helpers", reference_pkg = "cardx")) #' lm(AGE ~ ARM, data = cards::ADSL) |> #' ard_regression(add_estimate_to_reference_rows = TRUE) NULL @@ -25,8 +25,10 @@ ard_regression <- function(x, ...) { #' @rdname ard_regression #' @export ard_regression.default <- function(x, tidy_fun = broom.helpers::tidy_with_broom_or_parameters, ...) { + set_cli_abort_call() + # check installed packages --------------------------------------------------- - cards::check_pkg_installed("broom.helpers", reference_pkg = "cardx") + check_pkg_installed(pkg = "broom.helpers", reference_pkg = "cardx") # check inputs --------------------------------------------------------------- check_not_missing(x) diff --git a/R/ard_regression_basic.R b/R/ard_regression_basic.R index 2093cd8f2..e923245fb 100644 --- a/R/ard_regression_basic.R +++ b/R/ard_regression_basic.R @@ -26,7 +26,7 @@ #' @name ard_regression_basic #' @export #' -#' @examplesIf cards::is_pkg_installed("broom.helpers", reference_pkg = "cardx") +#' @examplesIf do.call(asNamespace("cardx")$is_pkg_installed, list(pkg = "broom.helpers", reference_pkg = "cardx")) #' lm(AGE ~ ARM, data = cards::ADSL) |> #' ard_regression_basic() ard_regression_basic <- function(x, tidy_fun = broom.helpers::tidy_with_broom_or_parameters, @@ -35,8 +35,10 @@ ard_regression_basic <- function(x, tidy_fun = broom.helpers::tidy_with_broom_or "label", "contrasts_type", "contrasts", "var_nlevels" ), ...) { + set_cli_abort_call() + # check installed packages --------------------------------------------------- - cards::check_pkg_installed("broom.helpers", reference_pkg = "cardx") + check_pkg_installed(pkg = "broom.helpers", reference_pkg = "cardx") # check inputs --------------------------------------------------------------- check_not_missing(x) diff --git a/R/ard_smd_smd.R b/R/ard_smd_smd.R index cb6c4ec8c..b468c9f1d 100644 --- a/R/ard_smd_smd.R +++ b/R/ard_smd_smd.R @@ -16,12 +16,14 @@ #' @return ARD data frame #' @export #' -#' @examplesIf cards::is_pkg_installed("smd", reference_pkg = "cardx") +#' @examplesIf do.call(asNamespace("cardx")$is_pkg_installed, list(pkg = "smd", reference_pkg = "cardx")) #' ard_smd_smd(cards::ADSL, by = ARM, variables = AGE, std.error = TRUE) #' ard_smd_smd(cards::ADSL, by = ARM, variables = AGEGR1, std.error = TRUE) ard_smd_smd <- function(data, by, variables, ...) { + set_cli_abort_call() + # check installed packages --------------------------------------------------- - cards::check_pkg_installed("smd", reference_pkg = "cardx") + check_pkg_installed("smd", reference_pkg = "cardx") # check/process inputs ------------------------------------------------------- check_not_missing(data) diff --git a/R/ard_stats_anova.R b/R/ard_stats_anova.R index 16059560b..4e4ef5f23 100644 --- a/R/ard_stats_anova.R +++ b/R/ard_stats_anova.R @@ -45,7 +45,7 @@ #' @return ARD data frame #' @name ard_stats_anova #' -#' @examplesIf cards::is_pkg_installed(c("broom", "withr", "lme4"), reference_pkg = "cardx") +#' @examplesIf do.call(asNamespace("cardx")$is_pkg_installed, list(pkg = c("broom", "withr", "lme4"), reference_pkg = "cardx")) #' anova( #' lm(mpg ~ am, mtcars), #' lm(mpg ~ am + hp, mtcars) @@ -77,9 +77,11 @@ ard_stats_anova <- function(x, ...) { #' @rdname ard_stats_anova #' @export ard_stats_anova.anova <- function(x, method = "ANOVA results from `stats::anova()`", ...) { + set_cli_abort_call() + # check inputs --------------------------------------------------------------- check_dots_empty() - cards::check_pkg_installed("broom", reference_pkg = "cardx") + check_pkg_installed("broom", reference_pkg = "cardx") check_string(method, message = "Argument {.arg method} must be a string of a function name.") # return df in cards formats ------------------------------------------------- @@ -102,10 +104,12 @@ ard_stats_anova.data.frame <- function(x, package = "base", method = "ANOVA results from `stats::anova()`", ...) { + set_cli_abort_call() + # check inputs --------------------------------------------------------------- check_dots_empty() check_string(package) - cards::check_pkg_installed(c("broom", "withr", package), reference_pkg = "cardx") + check_pkg_installed(c("broom", "withr", package), reference_pkg = "cardx") check_not_missing(formulas) check_not_missing(x) check_not_missing(fn) @@ -113,10 +117,13 @@ ard_stats_anova.data.frame <- function(x, check_data_frame(x) check_string(fn) if (str_detect(fn, "::")) { - cli::cli_abort(c( - "Argument {.arg fn} cannot be namespaced.", - i = "Put the package name in the {.arg package} argument." - )) + cli::cli_abort( + c( + "Argument {.arg fn} cannot be namespaced.", + i = "Put the package name in the {.arg package} argument." + ), + call = get_cli_abort_call() + ) } # calculate results and return df in cards formats --------------------------- diff --git a/R/ard_stats_aov.R b/R/ard_stats_aov.R index 3abdd4759..cc335102f 100644 --- a/R/ard_stats_aov.R +++ b/R/ard_stats_aov.R @@ -10,11 +10,13 @@ #' @return ARD data frame #' @export #' -#' @examplesIf cards::is_pkg_installed(c("broom.helpers"), reference_pkg = "cardx") +#' @examplesIf do.call(asNamespace("cardx")$is_pkg_installed, list(pkg = "broom.helpers", reference_pkg = "cardx")) #' ard_stats_aov(AGE ~ ARM, data = cards::ADSL) ard_stats_aov <- function(formula, data, ...) { + set_cli_abort_call() + # check installed packages --------------------------------------------------- - cards::check_pkg_installed(c("broom.helpers"), reference_pkg = "cardx") + check_pkg_installed(c("broom.helpers"), reference_pkg = "cardx") # check/process inputs ------------------------------------------------------- check_not_missing(formula) diff --git a/R/ard_stats_chisq_test.R b/R/ard_stats_chisq_test.R index 9f76c3118..b3dae0366 100644 --- a/R/ard_stats_chisq_test.R +++ b/R/ard_stats_chisq_test.R @@ -17,12 +17,14 @@ #' @return ARD data frame #' @export #' -#' @examplesIf cards::is_pkg_installed("broom", reference_pkg = "cardx") +#' @examplesIf do.call(asNamespace("cardx")$is_pkg_installed, list(pkg = "broom", reference_pkg = "cardx")) #' cards::ADSL |> #' ard_stats_chisq_test(by = "ARM", variables = "AGEGR1") ard_stats_chisq_test <- function(data, by, variables, ...) { + set_cli_abort_call() + # check installed packages --------------------------------------------------- - cards::check_pkg_installed("broom", reference_pkg = "cardx") + check_pkg_installed("broom", reference_pkg = "cardx") # check/process inputs ------------------------------------------------------- check_not_missing(data) diff --git a/R/ard_stats_fisher_test.R b/R/ard_stats_fisher_test.R index a48773c37..3402bd8e0 100644 --- a/R/ard_stats_fisher_test.R +++ b/R/ard_stats_fisher_test.R @@ -17,12 +17,14 @@ #' @return ARD data frame #' @export #' -#' @examplesIf cards::is_pkg_installed("broom", reference_pkg = "cardx") +#' @examplesIf do.call(asNamespace("cardx")$is_pkg_installed, list(pkg = "broom", reference_pkg = "cardx")) #' cards::ADSL[1:30, ] |> #' ard_stats_fisher_test(by = "ARM", variables = "AGEGR1") ard_stats_fisher_test <- function(data, by, variables, ...) { + set_cli_abort_call() + # check installed packages --------------------------------------------------- - cards::check_pkg_installed("broom", reference_pkg = "cardx") + check_pkg_installed("broom", reference_pkg = "cardx") # check/process inputs ------------------------------------------------------- check_not_missing(data) diff --git a/R/ard_stats_kruskal_test.R b/R/ard_stats_kruskal_test.R index 876d5af00..5a804c793 100644 --- a/R/ard_stats_kruskal_test.R +++ b/R/ard_stats_kruskal_test.R @@ -16,12 +16,14 @@ #' @return ARD data frame #' @export #' -#' @examplesIf cards::is_pkg_installed("broom", reference_pkg = "cardx") +#' @examplesIf do.call(asNamespace("cardx")$is_pkg_installed, list(pkg = "broom", reference_pkg = "cardx")) #' cards::ADSL |> #' ard_stats_kruskal_test(by = "ARM", variables = "AGE") ard_stats_kruskal_test <- function(data, by, variables) { + set_cli_abort_call() + # check installed packages --------------------------------------------------- - cards::check_pkg_installed("broom", reference_pkg = "cardx") + check_pkg_installed("broom", reference_pkg = "cardx") # check/process inputs ------------------------------------------------------- check_not_missing(data) diff --git a/R/ard_stats_mcnemar_test.R b/R/ard_stats_mcnemar_test.R index da932885c..07de733c0 100644 --- a/R/ard_stats_mcnemar_test.R +++ b/R/ard_stats_mcnemar_test.R @@ -20,12 +20,14 @@ #' The data is passed as `stats::mcnemar.test(x = data[[variable]], y = data[[by]], ...)`. #' Please use `table(x = data[[variable]], y = data[[by]])` to check the contingency table. #' -#' @examplesIf cards::is_pkg_installed("broom", reference_pkg = "cardx") +#' @examplesIf do.call(asNamespace("cardx")$is_pkg_installed, list(pkg = "broom", reference_pkg = "cardx")) #' cards::ADSL |> #' ard_stats_mcnemar_test(by = "SEX", variables = "EFFFL") ard_stats_mcnemar_test <- function(data, by, variables, ...) { + set_cli_abort_call() + # check installed packages --------------------------------------------------- - cards::check_pkg_installed("broom", reference_pkg = "cardx") + check_pkg_installed("broom", reference_pkg = "cardx") # check/process inputs ------------------------------------------------------- check_not_missing(data) diff --git a/R/ard_stats_mood_test.R b/R/ard_stats_mood_test.R index ad0bb5c8a..9473fac4e 100644 --- a/R/ard_stats_mood_test.R +++ b/R/ard_stats_mood_test.R @@ -22,12 +22,14 @@ #' @rdname ard_stats_mood_test #' @export #' -#' @examplesIf cards::is_pkg_installed("broom", reference_pkg = "cardx") +#' @examplesIf do.call(asNamespace("cardx")$is_pkg_installed, list(pkg = "broom", reference_pkg = "cardx")) #' cards::ADSL |> #' ard_stats_mood_test(by = "SEX", variables = "AGE") ard_stats_mood_test <- function(data, by, variables, ...) { + set_cli_abort_call() + # check installed packages --------------------------------------------------- - cards::check_pkg_installed("broom", reference_pkg = "cardx") + check_pkg_installed("broom", reference_pkg = "cardx") # check/process inputs ------------------------------------------------------- check_not_missing(data) diff --git a/R/ard_stats_oneway_test.R b/R/ard_stats_oneway_test.R index f2182b4ab..cc1d01773 100644 --- a/R/ard_stats_oneway_test.R +++ b/R/ard_stats_oneway_test.R @@ -10,11 +10,13 @@ #' @return ARD data frame #' @export #' -#' @examplesIf cards::is_pkg_installed(c("broom"), reference_pkg = "cardx") +#' @examplesIf do.call(asNamespace("cardx")$is_pkg_installed, list(pkg = "broom", reference_pkg = "cardx")) #' ard_stats_oneway_test(AGE ~ ARM, data = cards::ADSL) ard_stats_oneway_test <- function(formula, data, ...) { + set_cli_abort_call() + # check installed packages --------------------------------------------------- - cards::check_pkg_installed(c("broom"), reference_pkg = "cardx") + check_pkg_installed(c("broom"), reference_pkg = "cardx") # check/process inputs ------------------------------------------------------- check_not_missing(formula) diff --git a/R/ard_stats_prop_test.R b/R/ard_stats_prop_test.R index 6ef4a8b4d..ce3958c89 100644 --- a/R/ard_stats_prop_test.R +++ b/R/ard_stats_prop_test.R @@ -15,11 +15,15 @@ #' @return ARD data frame #' @export #' -#' @examplesIf cards::is_pkg_installed("broom", reference_pkg = "cardx") +#' @examplesIf do.call(asNamespace("cardx")$is_pkg_installed, list(pkg = "broom", reference_pkg = "cardx")) #' mtcars |> #' ard_stats_prop_test(by = vs, variables = am) ard_stats_prop_test <- function(data, by, variables, ...) { - cards::check_pkg_installed("broom", reference_pkg = "cardx") + set_cli_abort_call() + + # check installed packages --------------------------------------------------- + check_pkg_installed(pkg = "broom", reference_pkg = "cardx") + # check inputs --------------------------------------------------------------- check_not_missing(data) check_not_missing(variables) @@ -56,10 +60,13 @@ ard_stats_prop_test <- function(data, by, variables, ...) { ) if (nrow(data_counts) != 2) { - cli::cli_abort(c( - "The {.arg by} column must have exactly 2 levels.", - "The levels are {.val {data_counts[[by]]}}" - )) + cli::cli_abort( + c( + "The {.arg by} column must have exactly 2 levels.", + "The levels are {.val {data_counts[[by]]}}" + ), + call = get_cli_abort_call() + ) } stats::prop.test( diff --git a/R/ard_stats_t_test.R b/R/ard_stats_t_test.R index 2e1f9214e..6758fc5e6 100644 --- a/R/ard_stats_t_test.R +++ b/R/ard_stats_t_test.R @@ -27,7 +27,7 @@ #' The data are then passed as #' `t.test(x = data_wide[[]], y = data_wide[[]], paired = TRUE, ...)`. #' -#' @examplesIf cards::is_pkg_installed("broom", reference_pkg = "cardx") +#' @examplesIf do.call(asNamespace("cardx")$is_pkg_installed, list(pkg = "broom", reference_pkg = "cardx")) #' cards::ADSL |> #' dplyr::filter(ARM %in% c("Placebo", "Xanomeline High Dose")) |> #' ard_stats_t_test(by = ARM, variables = c(AGE, BMIBL)) @@ -44,8 +44,10 @@ NULL #' @rdname ard_stats_t_test #' @export ard_stats_t_test <- function(data, variables, by = NULL, ...) { + set_cli_abort_call() + # check installed packages --------------------------------------------------- - cards::check_pkg_installed("broom", reference_pkg = "cardx") + check_pkg_installed("broom", reference_pkg = "cardx") # check/process inputs ------------------------------------------------------- check_not_missing(data) @@ -85,8 +87,10 @@ ard_stats_t_test <- function(data, variables, by = NULL, ...) { #' @rdname ard_stats_t_test #' @export ard_stats_paired_t_test <- function(data, by, variables, id, ...) { + set_cli_abort_call() + # check installed packages --------------------------------------------------- - cards::check_pkg_installed("broom", reference_pkg = "cardx") + check_pkg_installed("broom", reference_pkg = "cardx") # check/process inputs ------------------------------------------------------- check_not_missing(data) @@ -190,7 +194,6 @@ ard_stats_paired_t_test <- function(data, by, variables, id, ...) { #' @param by (`string`)\cr by column name #' @param variable (`string`)\cr variable column name #' @param id (`string`)\cr subject id column name -#' @param env (`environment`) used for error messaging. Default is `rlang::caller_env()` #' #' @return a wide data frame #' @keywords internal @@ -200,10 +203,12 @@ ard_stats_paired_t_test <- function(data, by, variables, id, ...) { #' dplyr::mutate(.by = ARM, USUBJID = dplyr::row_number()) |> #' dplyr::arrange(USUBJID, ARM) |> #' cardx:::.paired_data_pivot_wider(by = "ARM", variable = "AGE", id = "USUBJID") -.paired_data_pivot_wider <- function(data, by, variable, id, env = rlang::caller_env()) { +.paired_data_pivot_wider <- function(data, by, variable, id) { # check the number of levels before pivoting data to wider format if (dplyr::n_distinct(data[[by]], na.rm = TRUE) != 2L) { - cli::cli_abort("The {.arg by} argument must have two and only two levels.", call = env) + cli::cli_abort("The {.arg by} argument must have two and only two levels.", + call = get_cli_abort_call() + ) } data |> diff --git a/R/ard_stats_wilcox_test.R b/R/ard_stats_wilcox_test.R index 7e31f6822..e4a1048e4 100644 --- a/R/ard_stats_wilcox_test.R +++ b/R/ard_stats_wilcox_test.R @@ -27,7 +27,7 @@ #' The data are then passed as #' `wilcox.test(x = data_wide[[]], y = data_wide[[]], paired = TRUE, ...)`. #' -#' @examplesIf cards::is_pkg_installed("broom", reference_pkg = "cardx") +#' @examplesIf do.call(asNamespace("cardx")$is_pkg_installed, list(pkg = "broom", reference_pkg = "cardx")) #' cards::ADSL |> #' dplyr::filter(ARM %in% c("Placebo", "Xanomeline High Dose")) |> #' ard_stats_wilcox_test(by = "ARM", variables = "AGE") @@ -44,8 +44,10 @@ NULL #' @rdname ard_stats_wilcox_test #' @export ard_stats_wilcox_test <- function(data, variables, by = NULL, ...) { + set_cli_abort_call() + # check installed packages --------------------------------------------------- - cards::check_pkg_installed("broom", reference_pkg = "cardx") + check_pkg_installed("broom", reference_pkg = "cardx") # check/process inputs ------------------------------------------------------- check_not_missing(data) @@ -91,8 +93,10 @@ ard_stats_wilcox_test <- function(data, variables, by = NULL, ...) { #' @rdname ard_stats_wilcox_test #' @export ard_stats_paired_wilcox_test <- function(data, by, variables, id, ...) { + set_cli_abort_call() + # check installed packages --------------------------------------------------- - cards::check_pkg_installed("broom", reference_pkg = "cardx") + check_pkg_installed("broom", reference_pkg = "cardx") # check/process inputs ------------------------------------------------------- check_not_missing(data) @@ -193,40 +197,6 @@ ard_stats_paired_wilcox_test <- function(data, by, variables, id, ...) { } -#' Convert long paired data to wide -#' -#' -#' @param data (`data.frame`)\cr a data frame that is one line per subject per group -#' @param by (`string`)\cr by column name -#' @param variable (`string`)\cr variable column name -#' @param id (`string`)\cr subject id column name -#' @param env (`environment`) used for error messaging. Default is `rlang::caller_env()` -#' -#' @return a wide data frame -#' @keywords internal -#' @examples -#' cards::ADSL[c("ARM", "AGE")] |> -#' dplyr::filter(ARM %in% c("Placebo", "Xanomeline High Dose")) |> -#' dplyr::mutate(.by = ARM, USUBJID = dplyr::row_number()) |> -#' dplyr::arrange(USUBJID, ARM) |> -#' cardx:::.paired_data_pivot_wider(by = "ARM", variable = "AGE", id = "USUBJID") -.paired_data_pivot_wider <- function(data, by, variable, id, env = rlang::caller_env()) { - # check the number of levels before pivoting data to wider format - if (dplyr::n_distinct(data[[by]], na.rm = TRUE) != 2L) { - cli::cli_abort("The {.arg by} argument must have two and only two levels.", call = env) - } - - data |> - # arrange data so the first group always appears first - dplyr::arrange(.data[[by]]) |> - tidyr::pivot_wider( - id_cols = all_of(id), - names_from = all_of(by), - values_from = all_of(variable) - ) |> - stats::setNames(c(id, "by1", "by2")) -} - .df_wilcoxtest_stat_labels <- function(by = NULL) { dplyr::tribble( ~stat_name, ~stat_label, diff --git a/R/ard_survey_svychisq.R b/R/ard_survey_svychisq.R index 2ae37c743..91ea9c77a 100644 --- a/R/ard_survey_svychisq.R +++ b/R/ard_survey_svychisq.R @@ -20,14 +20,16 @@ #' @return ARD data frame #' @export #' -#' @examplesIf cards::is_pkg_installed(c("survey", "broom"), reference_pkg = "cardx") +#' @examplesIf do.call(asNamespace("cardx")$is_pkg_installed, list(pkg = c("survey", "broom"), reference_pkg = "cardx")) #' data(api, package = "survey") #' dclus1 <- survey::svydesign(id = ~dnum, weights = ~pw, data = apiclus1, fpc = ~fpc) #' #' ard_survey_svychisq(dclus1, variables = sch.wide, by = comp.imp, statistic = "F") ard_survey_svychisq <- function(data, by, variables, statistic = "F", ...) { + set_cli_abort_call() + # check installed packages --------------------------------------------------- - cards::check_pkg_installed(c("survey", "broom"), reference_pkg = "cardx") + check_pkg_installed(c("survey", "broom"), reference_pkg = "cardx") # check/process inputs ------------------------------------------------------- check_not_missing(data) diff --git a/R/ard_survey_svycontinuous.R b/R/ard_survey_svycontinuous.R index 392eabdbe..88341edd4 100644 --- a/R/ard_survey_svycontinuous.R +++ b/R/ard_survey_svycontinuous.R @@ -34,7 +34,7 @@ #' @return an ARD data frame of class 'card' #' @export #' -#' @examplesIf cards::is_pkg_installed("survey", reference_pkg = "cardx") +#' @examplesIf do.call(asNamespace("cardx")$is_pkg_installed, list(pkg = "survey", reference_pkg = "cardx")) #' data(api, package = "survey") #' dclus1 <- survey::svydesign(id = ~dnum, weights = ~pw, data = apiclus1, fpc = ~fpc) #' @@ -47,7 +47,10 @@ ard_survey_svycontinuous <- function(data, variables, by = NULL, statistic = everything() ~ c("median", "p25", "p75"), fmt_fn = NULL, stat_label = NULL) { - cards::check_pkg_installed("survey", reference_pkg = "cardx") + set_cli_abort_call() + + # check installed packages --------------------------------------------------- + check_pkg_installed(pkg = "survey", reference_pkg = "cardx") # check inputs --------------------------------------------------------------- check_not_missing(data) diff --git a/R/ard_survey_svyranktest.R b/R/ard_survey_svyranktest.R index 3d7fa3c4f..8116c25ae 100644 --- a/R/ard_survey_svyranktest.R +++ b/R/ard_survey_svyranktest.R @@ -17,7 +17,7 @@ #' @return ARD data frame #' @export #' -#' @examplesIf cards::is_pkg_installed(c("survey", "broom"), reference_pkg = "cardx") +#' @examplesIf do.call(asNamespace("cardx")$is_pkg_installed, list(pkg = c("survey", "broom"), reference_pkg = "cardx")) #' data(api, package = "survey") #' dclus2 <- survey::svydesign(id = ~ dnum + snum, fpc = ~ fpc1 + fpc2, data = apiclus2) #' @@ -26,8 +26,10 @@ #' ard_survey_svyranktest(dclus2, variables = enroll, by = comp.imp, test = "median") #' ard_survey_svyranktest(dclus2, variables = enroll, by = comp.imp, test = "KruskalWallis") ard_survey_svyranktest <- function(data, by, variables, test, ...) { + set_cli_abort_call() + # check installed packages --------------------------------------------------- - cards::check_pkg_installed(c("survey", "broom"), reference_pkg = "cardx") + check_pkg_installed(c("survey", "broom"), reference_pkg = "cardx") # check/process inputs ------------------------------------------------------- check_not_missing(data) diff --git a/R/ard_survey_svyttest.R b/R/ard_survey_svyttest.R index d3f01c95b..da2a1c690 100644 --- a/R/ard_survey_svyttest.R +++ b/R/ard_survey_svyttest.R @@ -17,14 +17,16 @@ #' @return ARD data frame #' @export #' -#' @examplesIf cards::is_pkg_installed(c("survey", "broom"), reference_pkg = "cardx") +#' @examplesIf do.call(asNamespace("cardx")$is_pkg_installed, list(pkg = c("survey", "broom"), reference_pkg = "cardx")) #' data(api, package = "survey") #' dclus2 <- survey::svydesign(id = ~ dnum + snum, fpc = ~ fpc1 + fpc2, data = apiclus2) #' #' ard_survey_svyttest(dclus2, variables = enroll, by = comp.imp, conf.level = 0.9) ard_survey_svyttest <- function(data, by, variables, conf.level = 0.95, ...) { + set_cli_abort_call() + # check installed packages --------------------------------------------------- - cards::check_pkg_installed(c("survey", "broom"), reference_pkg = "cardx") + check_pkg_installed(c("survey", "broom"), reference_pkg = "cardx") # check/process inputs ------------------------------------------------------- check_not_missing(data) diff --git a/R/ard_survival_survfit.R b/R/ard_survival_survfit.R index 5dcd7ca55..1022119a7 100644 --- a/R/ard_survival_survfit.R +++ b/R/ard_survival_survfit.R @@ -32,7 +32,7 @@ #' * Times should be provided using the same scale as the time variable used to fit the provided #' survival fit model. #' -#' @examplesIf cards::is_pkg_installed(c("survival", "broom"), reference_pkg = "cardx") +#' @examplesIf do.call(asNamespace("cardx")$is_pkg_installed, list(pkg = c("survival", "broom"), reference_pkg = "cardx")) #' library(survival) #' #' survfit(Surv(AVAL, CNSR) ~ TRTA, cards::ADTTE) |> @@ -59,19 +59,25 @@ NULL #' @rdname ard_survival_survfit #' @export ard_survival_survfit <- function(x, times = NULL, probs = NULL, type = NULL) { + set_cli_abort_call() + # check installed packages --------------------------------------------------- - cards::check_pkg_installed(c("survival", "broom"), reference_pkg = "cardx") + check_pkg_installed(c("survival", "broom"), reference_pkg = "cardx") # check/process inputs ------------------------------------------------------- check_not_missing(x) check_class(x, cls = "survfit") if (inherits(x, "survfitcox")) { - cli::cli_abort("Argument {.arg x} cannot be class {.cls survfitcox}.") + cli::cli_abort("Argument {.arg x} cannot be class {.cls survfitcox}.", + call = get_cli_abort_call() + ) } # competing risks models cannot use the type argument if (inherits(x, c("survfitms", "survfitcoxms")) && !is.null(type)) { - cli::cli_abort("Cannot use {.arg type} argument with {.code survfit} models with class {.cls {c('survfitms', 'survfitcoxms')}}.") + cli::cli_abort("Cannot use {.arg type} argument with {.code survfit} models with class {.cls {c('survfitms', 'survfitcoxms')}}.", + call = get_cli_abort_call() + ) } if (!is.null(probs)) check_range(probs, c(0, 1)) if (sum(is.null(times), is.null(probs)) != 1) { @@ -85,7 +91,9 @@ ard_survival_survfit <- function(x, times = NULL, probs = NULL, type = NULL) { # cannot specify type arg when probs supplied if (!is.null(probs) && !is.null(type)) { - cli::cli_abort("Cannot use {.arg type} argument when {.arg probs} argument specifed.") + cli::cli_abort("Cannot use {.arg type} argument when {.arg probs} argument specifed.", + call = get_cli_abort_call() + ) } # build ARD ------------------------------------------------------------------ diff --git a/R/import-standalone-check_pkg_installed.R b/R/import-standalone-check_pkg_installed.R new file mode 100644 index 000000000..8f6522da3 --- /dev/null +++ b/R/import-standalone-check_pkg_installed.R @@ -0,0 +1,211 @@ +# Standalone file: do not edit by hand +# Source: +# ---------------------------------------------------------------------- +# +# --- +# repo: ddsjoberg/standalone +# file: standalone-check_pkg_installed.R +# last-updated: 2024-04-10 +# license: https://unlicense.org +# dependencies: standalone-cli_call_env.R +# imports: [rlang, dplyr, tidyr] +# --- +# +# This file provides functions to check package installation. +# +# ## Changelog +# nocov start +# styler: off + +#' Check Package Installation +#' +#' @description +#' - `check_pkg_installed()`: checks whether a package is installed and +#' returns an error if not available, or interactively asks user to install +#' missing dependency. If a package search is provided, +#' the function will check whether a minimum version of a package is required and installed. +#' +#' - `is_pkg_installed()`: checks whether a package is installed and +#' returns `TRUE` or `FALSE` depending on availability. If a package search is provided, +#' the function will check whether a minimum version of a package is required and installed. +#' +#' - `get_pkg_dependencies()` returns a tibble with all +#' dependencies of a specific package. +#' +#' - `get_min_version_required()` will return, if any, the minimum version +#' of `pkg` required by `reference_pkg`. +#' +#' @param pkg (`character`)\cr +#' vector of package names to check. +#' @param call (`environment`)\cr +#' frame for error messaging. Default is [get_cli_abort_call()]. +#' @param reference_pkg (`string`)\cr +#' name of the package the function will search for a minimum required version from. +#' @param lib.loc (`path`)\cr +#' location of `R` library trees to search through, see [utils::packageDescription()]. +#' +#' @return `is_pkg_installed()` and `check_pkg_installed()` returns a logical or error, +#' `get_min_version_required()` returns a data frame with the minimum version required, +#' `get_pkg_dependencies()` returns a tibble. +#' +#' @examples +#' check_pkg_installed("dplyr") +#' +#' is_pkg_installed("dplyr") +#' +#' get_pkg_dependencies() +#' +#' get_min_version_required("dplyr") +#' +#' @name check_pkg_installed +#' @noRd +NULL + +#' @inheritParams check_pkg_installed +#' @keywords internal +#' @noRd +check_pkg_installed <- function(pkg, + reference_pkg = "cards", + call = get_cli_abort_call()) { + set_cli_abort_call() + + # check inputs --------------------------------------------------------------- + check_not_missing(pkg) + check_class(pkg, cls = "character") + check_string(reference_pkg, allow_empty = TRUE) + + # get min version data ------------------------------------------------------- + df_pkg_min_version <- + get_min_version_required(pkg = pkg, reference_pkg = reference_pkg, call = call) + + # prompt user to install package --------------------------------------------- + rlang::check_installed( + pkg = df_pkg_min_version$pkg, + version = df_pkg_min_version$version, + compare = df_pkg_min_version$compare, + call = call + ) |> + # this can be removed after this issue is resolved https://github.com/r-lib/rlang/issues/1694 + suppressWarnings() +} + +#' @inheritParams check_pkg_installed +#' @keywords internal +#' @noRd +is_pkg_installed <- function(pkg, + reference_pkg = "cards", + call = get_cli_abort_call()) { + set_cli_abort_call() + + # check inputs --------------------------------------------------------------- + check_not_missing(pkg) + check_class(pkg, cls = "character") + check_string(reference_pkg, allow_empty = TRUE) + + # get min version data ------------------------------------------------------- + df_pkg_min_version <- + get_min_version_required(pkg = pkg, reference_pkg = reference_pkg, call = call) + + # check installation TRUE/FALSE ---------------------------------------------- + rlang::is_installed( + pkg = df_pkg_min_version$pkg, + version = df_pkg_min_version$version, + compare = df_pkg_min_version$compare + ) |> + # this can be removed after this issue is resolved https://github.com/r-lib/rlang/issues/1694 + suppressWarnings() +} + +#' @inheritParams check_pkg_installed +#' @keywords internal +#' @noRd +get_pkg_dependencies <- function(reference_pkg = "cards", lib.loc = NULL, call = get_cli_abort_call()) { + set_cli_abort_call() + + check_string(reference_pkg, allow_empty = TRUE, call = call) + + if (rlang::is_empty(reference_pkg)) { + return(.empty_pkg_deps_df()) + } + + description <- utils::packageDescription(reference_pkg, lib.loc = lib.loc) |> suppressWarnings() + if (identical(description, NA)) { + return(.empty_pkg_deps_df()) + } + description |> + unclass() |> + dplyr::as_tibble() |> + dplyr::select( + dplyr::any_of(c( + "Package", "Version", "Imports", "Depends", + "Suggests", "Enhances", "LinkingTo" + )) + ) |> + dplyr::rename( + reference_pkg = "Package", + reference_pkg_version = "Version" + ) |> + tidyr::pivot_longer( + -dplyr::all_of(c("reference_pkg", "reference_pkg_version")), + values_to = "pkg", + names_to = "dependency_type", + ) |> + tidyr::separate_rows("pkg", sep = ",") |> + dplyr::mutate(pkg = str_squish(.data$pkg)) |> + dplyr::filter(!is.na(.data$pkg)) |> + tidyr::separate( + .data$pkg, + into = c("pkg", "version"), + sep = " ", extra = "merge", fill = "right" + ) |> + dplyr::mutate( + compare = .data$version |> str_extract(pattern = "[>=<]+"), + version = .data$version |> str_remove_all(pattern = "[\\(\\) >=<]") + ) +} + +.empty_pkg_deps_df <- function() { + dplyr::tibble( + reference_pkg = character(0L), reference_pkg_version = character(0L), + dependency_type = character(0L), pkg = character(0L), + version = character(0L), compare = character(0L) + ) +} + +#' @inheritParams check_pkg_installed +#' @keywords internal +#' @noRd +get_min_version_required <- function(pkg, reference_pkg = "cards", + lib.loc = NULL, call = get_cli_abort_call()) { + set_cli_abort_call() + + check_not_missing(pkg, call = call) + check_class(pkg, cls = "character", call = call) + check_string(reference_pkg, allow_empty = TRUE, call = call) + + # if no package reference, return a df with just the pkg names + if (rlang::is_empty(reference_pkg)) { + return( + .empty_pkg_deps_df() |> + dplyr::full_join( + dplyr::tibble(pkg = pkg), + by = "pkg" + ) + ) + } + + # get the package_ref deps and subset on requested pkgs, also supplement df with pkgs + # that may not be proper deps of the reference package (these pkgs don't have min versions) + res <- + get_pkg_dependencies(reference_pkg, lib.loc = lib.loc) |> + dplyr::filter(.data$pkg %in% .env$pkg) |> + dplyr::full_join( + dplyr::tibble(pkg = pkg), + by = "pkg" + ) + + res +} + +# nocov end +# styler: on diff --git a/R/import-standalone-checks.R b/R/import-standalone-checks.R index 252cb1048..5d1379822 100644 --- a/R/import-standalone-checks.R +++ b/R/import-standalone-checks.R @@ -5,8 +5,9 @@ # --- # repo: ddsjoberg/standalone # file: standalone-checks.R -# last-updated: 2024-01-24 +# last-updated: 2024-04-10 # license: https://unlicense.org +# dependencies: standalone-cli_call_env.R # imports: [rlang, cli] # --- # @@ -49,7 +50,7 @@ check_class <- function(x, ), arg_name = rlang::caller_arg(x), class = "check_class", - call = parent.frame()) { + call = get_cli_abort_call()) { # if empty, skip test if (isTRUE(allow_empty) && rlang::is_empty(x)) { return(invisible(x)) @@ -78,7 +79,7 @@ check_data_frame <- function(x, ), arg_name = rlang::caller_arg(x), class = "check_data_frame", - call = parent.frame()) { + call = get_cli_abort_call()) { check_class( x = x, cls = "data.frame", allow_empty = allow_empty, message = message, arg_name = arg_name, class = class, call = call @@ -102,7 +103,7 @@ check_logical <- function(x, ), arg_name = rlang::caller_arg(x), class = "check_logical", - call = parent.frame()) { + call = get_cli_abort_call()) { check_class( x = x, cls = "logical", allow_empty = allow_empty, message = message, arg_name = arg_name, class = class, call = call @@ -126,7 +127,7 @@ check_scalar_logical <- function(x, ), arg_name = rlang::caller_arg(x), class = "check_scalar_logical", - call = parent.frame()) { + call = get_cli_abort_call()) { check_logical( x = x, allow_empty = allow_empty, message = message, arg_name = arg_name, @@ -157,7 +158,7 @@ check_string <- function(x, ), arg_name = rlang::caller_arg(x), class = "check_string", - call = parent.frame()) { + call = get_cli_abort_call()) { check_class( x = x, cls = "character", allow_empty = allow_empty, message = message, arg_name = arg_name, @@ -180,7 +181,7 @@ check_not_missing <- function(x, message = "The {.arg {arg_name}} argument cannot be missing.", arg_name = rlang::caller_arg(x), class = "check_not_missing", - call = parent.frame()) { + call = get_cli_abort_call()) { if (missing(x)) { cli::cli_abort(message, class = c(class, "standalone-checks"), call = call) } @@ -206,7 +207,7 @@ check_length <- function(x, length, allow_empty = FALSE, arg_name = rlang::caller_arg(x), class = "check_length", - call = parent.frame()) { + call = get_cli_abort_call()) { # if empty, skip test if (isTRUE(allow_empty) && rlang::is_empty(x)) { return(invisible(x)) @@ -235,7 +236,7 @@ check_scalar <- function(x, ), arg_name = rlang::caller_arg(x), class = "check_scalar", - call = parent.frame()) { + call = get_cli_abort_call()) { check_length( x = x, length = 1L, message = message, allow_empty = allow_empty, arg_name = arg_name, @@ -264,7 +265,7 @@ check_range <- function(x, allow_empty = FALSE, arg_name = rlang::caller_arg(x), class = "check_range", - call = parent.frame()) { + call = get_cli_abort_call()) { # if empty, skip test if (isTRUE(allow_empty) && rlang::is_empty(x)) { return(invisible(x)) @@ -322,7 +323,7 @@ check_scalar_range <- function(x, and length {.val {1}}.", arg_name = rlang::caller_arg(x), class = "check_scalar_range", - call = parent.frame()) { + call = get_cli_abort_call()) { check_scalar(x, message = message, arg_name = arg_name, allow_empty = allow_empty, class = class, call = call) @@ -355,7 +356,7 @@ check_binary <- function(x, ), arg_name = rlang::caller_arg(x), class = "check_binary", - call = parent.frame()) { + call = get_cli_abort_call()) { # if empty, skip test if (isTRUE(allow_empty) && rlang::is_empty(x)) { return(invisible(x)) @@ -398,7 +399,7 @@ check_formula_list_selector <- function(x, ), arg_name = rlang::caller_arg(x), class = "check_formula_list_selector", - call = parent.frame()) { + call = get_cli_abort_call()) { # if empty, skip test if (isTRUE(allow_empty) && rlang::is_empty(x)) { return(invisible(x)) diff --git a/R/import-standalone-cli_call_env.R b/R/import-standalone-cli_call_env.R new file mode 100644 index 000000000..88ccd6934 --- /dev/null +++ b/R/import-standalone-cli_call_env.R @@ -0,0 +1,53 @@ +# Standalone file: do not edit by hand +# Source: +# ---------------------------------------------------------------------- +# +# --- +# repo: ddsjoberg/standalone +# file: standalone-cli_call_env.R +# last-updated: 2024-04-10 +# license: https://unlicense.org +# imports: [rlang, cli] +# --- +# +# This file provides functions to set and access the call environment to use in cli::cli_abort() in check functions. +# +# ## Changelog +# nocov start +# styler: off + +#' Set Call Environment for [cli::cli_abort()] +#' +#' Set a call environment to be used as the `call` parameter in [cli::cli_abort()] for package checks. This function +#' is used to ensure that the correct user-facing function is reported for errors generated by internal checks that +#' use [cli::cli_abort()]. +#' +#' @param env (`enviroment`)\cr +#' call environment used as the `call` parameter in [cli::cli_abort()] for package checks +#' +#' @seealso [get_cli_abort_call()] +#' +#' @keywords internal +#' @noRd +set_cli_abort_call <- function(env = rlang::caller_env()) { + if (getOption("cli_abort_call") |> is.null()) { + options(cli_abort_call = env) + set_call <- as.call(list(function() options(cli_abort_call = NULL))) + do.call(on.exit, list(expr = set_call, after = FALSE), envir = env) + } + invisible() +} + +#' Get Call Environment for [cli::cli_abort()] +#' +#' @inheritParams set_cli_abort_call +#' @seealso [set_cli_abort_call()] +#' +#' @keywords internal +#' @noRd +get_cli_abort_call <- function() { + getOption("cli_abort_call", default = parent.frame()) +} + +# nocov end +# styler: on diff --git a/R/import-standalone-forcats.R b/R/import-standalone-forcats.R index f3370a2f2..db001fd9e 100644 --- a/R/import-standalone-forcats.R +++ b/R/import-standalone-forcats.R @@ -2,7 +2,6 @@ # Source: # ---------------------------------------------------------------------- # -# DO NOT MODIFY THIS FILE. INSTEAD MODIFY THE VERSION IN https://github.com/ddsjoberg/standalone/tree/main/R # --- # file: standalone-forcats.R # last-updated: 2024-01-24 diff --git a/R/import-standalone-stringr.R b/R/import-standalone-stringr.R index 3fb357e40..263bde5bc 100644 --- a/R/import-standalone-stringr.R +++ b/R/import-standalone-stringr.R @@ -2,12 +2,11 @@ # Source: # ---------------------------------------------------------------------- # -# DO NOT MODIFY THIS FILE. INSTEAD MODIFY THE VERSION IN https://github.com/ddsjoberg/standalone/tree/main/R # --- # file: standalone-stringr.R # last-updated: 2024-01-24 # license: https://unlicense.org -# imports: +# imports: rlang # --- # # This file provides a minimal shim to provide a stringr-like API on top of diff --git a/R/proportion_ci.R b/R/proportion_ci.R index d2b8e4c61..7c4dc069a 100644 --- a/R/proportion_ci.R +++ b/R/proportion_ci.R @@ -7,7 +7,7 @@ #' @return Confidence interval of a proportion. #' #' @name proportion_ci -#' @examplesIf cards::is_pkg_installed("broom", reference_pkg = "cardx") +#' @examplesIf do.call(asNamespace("cardx")$is_pkg_installed, list(pkg = "broom", reference_pkg = "cardx")) #' x <- c( #' TRUE, TRUE, TRUE, TRUE, TRUE, #' FALSE, FALSE, FALSE, FALSE, FALSE @@ -29,6 +29,8 @@ NULL #' #' @export proportion_ci_wald <- function(x, conf.level = 0.95, correct = FALSE) { + set_cli_abort_call() + # check inputs --------------------------------------------------------------- check_not_missing(x) check_binary(x) @@ -70,7 +72,10 @@ proportion_ci_wald <- function(x, conf.level = 0.95, correct = FALSE) { #' #' @export proportion_ci_wilson <- function(x, conf.level = 0.95, correct = FALSE) { - cards::check_pkg_installed("broom", reference_pkg = "cardx") + set_cli_abort_call() + + # check installed packages --------------------------------------------------- + check_pkg_installed(pkg = "broom", reference_pkg = "cardx") # check inputs --------------------------------------------------------------- check_not_missing(x) @@ -105,7 +110,11 @@ proportion_ci_wilson <- function(x, conf.level = 0.95, correct = FALSE) { #' #' @export proportion_ci_clopper_pearson <- function(x, conf.level = 0.95) { - cards::check_pkg_installed("broom", reference_pkg = "cardx") + set_cli_abort_call() + + # check installed packages --------------------------------------------------- + check_pkg_installed(pkg = "broom", reference_pkg = "cardx") + # check inputs --------------------------------------------------------------- check_not_missing(x) check_binary(x) @@ -132,6 +141,8 @@ proportion_ci_clopper_pearson <- function(x, conf.level = 0.95) { #' #' @export proportion_ci_agresti_coull <- function(x, conf.level = 0.95) { + set_cli_abort_call() + # check inputs --------------------------------------------------------------- check_not_missing(x) check_binary(x) @@ -173,6 +184,8 @@ proportion_ci_agresti_coull <- function(x, conf.level = 0.95) { #' #' @export proportion_ci_jeffreys <- function(x, conf.level = 0.95) { + set_cli_abort_call() + # check inputs --------------------------------------------------------------- check_not_missing(x) check_binary(x) @@ -258,6 +271,8 @@ proportion_ci_strat_wilson <- function(x, conf.level = 0.95, max.iterations = 10L, correct = FALSE) { + set_cli_abort_call() + # check inputs --------------------------------------------------------------- check_not_missing(x) check_not_missing(strata) diff --git a/inst/WORDLIST b/inst/WORDLIST index 820556d85..4b9ae88ff 100644 --- a/inst/WORDLIST +++ b/inst/WORDLIST @@ -18,6 +18,7 @@ XG Xin agresti anova +cli clopper coull de diff --git a/man/ard_aod_wald_test.Rd b/man/ard_aod_wald_test.Rd index 1ebc3b0f5..2469ac1ba 100644 --- a/man/ard_aod_wald_test.Rd +++ b/man/ard_aod_wald_test.Rd @@ -19,7 +19,7 @@ Function takes a regression model object and calculates Wald statistical test using \code{\link[aod:wald.test]{aod::wald.test()}}. } \examples{ -\dontshow{if (cards::is_pkg_installed(c("aod"), reference_pkg = "cardx")) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +\dontshow{if (do.call(asNamespace("cardx")$is_pkg_installed, list(pkg = "aod", reference_pkg = "cardx"))) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} lm(AGE ~ ARM, data = cards::ADSL) |> ard_aod_wald_test() \dontshow{\}) # examplesIf} diff --git a/man/ard_car_anova.Rd b/man/ard_car_anova.Rd index 0a7df8c1b..3b300f4ad 100644 --- a/man/ard_car_anova.Rd +++ b/man/ard_car_anova.Rd @@ -18,7 +18,7 @@ data frame Function takes a regression model object and calculated ANOVA using \code{\link[car:Anova]{car::Anova()}}. } \examples{ -\dontshow{if (cards::is_pkg_installed(c("broom.helpers", "car"), reference_pkg = "cardx")) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +\dontshow{if (do.call(asNamespace("cardx")$is_pkg_installed, list(pkg = c("broom.helpers", "car"), reference_pkg = "cardx"))) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} lm(AGE ~ ARM, data = cards::ADSL) |> ard_car_anova() diff --git a/man/ard_car_vif.Rd b/man/ard_car_vif.Rd index 0ddbfa572..994a3863e 100644 --- a/man/ard_car_vif.Rd +++ b/man/ard_car_vif.Rd @@ -20,6 +20,8 @@ Function takes a regression model object and returns the variance inflation fact using \code{\link[car:vif]{car::vif()}} and converts it to a ARD structure } \examples{ +\dontshow{if (do.call(asNamespace("cardx")$is_pkg_installed, list(pkg = "car", reference_pkg = "cardx"))) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} lm(AGE ~ ARM + SEX, data = cards::ADSL) |> ard_car_vif() +\dontshow{\}) # examplesIf} } diff --git a/man/ard_effectsize_cohens_d.Rd b/man/ard_effectsize_cohens_d.Rd index a0d1f5a20..3eb2ac94e 100644 --- a/man/ard_effectsize_cohens_d.Rd +++ b/man/ard_effectsize_cohens_d.Rd @@ -43,7 +43,7 @@ The data are then passed as \verb{effectsize::cohens_d(x = data_wide[[]], y = data_wide[[]], paired = TRUE, ...)}. } \examples{ -\dontshow{if (cards::is_pkg_installed(c("effectsize", "parameters"), reference_pkg = "cardx")) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +\dontshow{if (do.call(asNamespace("cardx")$is_pkg_installed, list(pkg = c("effectsize", "parameters"), reference_pkg = "cardx"))) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} cards::ADSL |> dplyr::filter(ARM \%in\% c("Placebo", "Xanomeline High Dose")) |> ard_effectsize_cohens_d(by = ARM, variables = AGE) diff --git a/man/ard_effectsize_hedges_g.Rd b/man/ard_effectsize_hedges_g.Rd index e726614f1..5ec59117a 100644 --- a/man/ard_effectsize_hedges_g.Rd +++ b/man/ard_effectsize_hedges_g.Rd @@ -43,7 +43,7 @@ The data are then passed as \verb{effectsize::hedges_g(x = data_wide[[]], y = data_wide[[]], paired = TRUE, ...)}. } \examples{ -\dontshow{if (cards::is_pkg_installed(c("effectsize", "parameters", "withr"), reference_pkg = "cardx")) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +\dontshow{if (do.call(asNamespace("cardx")$is_pkg_installed, list(pkg = c("effectsize", "parameters", "withr"), reference_pkg = "cardx"))) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} cards::ADSL |> dplyr::filter(ARM \%in\% c("Placebo", "Xanomeline High Dose")) |> ard_effectsize_hedges_g(by = ARM, variables = AGE) diff --git a/man/ard_proportion_ci.Rd b/man/ard_proportion_ci.Rd index 2d3ea6a9f..50349110b 100644 --- a/man/ard_proportion_ci.Rd +++ b/man/ard_proportion_ci.Rd @@ -47,7 +47,7 @@ an ARD data frame Calculate confidence intervals for proportions. } \examples{ -\dontshow{if (cards::is_pkg_installed("broom", reference_pkg = "cardx")) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +\dontshow{if (do.call(asNamespace("cardx")$is_pkg_installed, list(pkg = "broom", reference_pkg = "cardx"))) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} ard_proportion_ci(mtcars, variables = c(vs, am), method = "wilson") \dontshow{\}) # examplesIf} } diff --git a/man/ard_regression.Rd b/man/ard_regression.Rd index db2077c48..10b423c69 100644 --- a/man/ard_regression.Rd +++ b/man/ard_regression.Rd @@ -25,7 +25,7 @@ Function takes a regression model object and converts it to a ARD structure using the \code{broom.helpers} package. } \examples{ -\dontshow{if (cards::is_pkg_installed("broom.helpers", reference_pkg = "cardx")) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +\dontshow{if (do.call(asNamespace("cardx")$is_pkg_installed, list(pkg = "broom.helpers", reference_pkg = "cardx"))) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} lm(AGE ~ ARM, data = cards::ADSL) |> ard_regression(add_estimate_to_reference_rows = TRUE) \dontshow{\}) # examplesIf} diff --git a/man/ard_regression_basic.Rd b/man/ard_regression_basic.Rd index f2a2be0c1..8d500a6b3 100644 --- a/man/ard_regression_basic.Rd +++ b/man/ard_regression_basic.Rd @@ -44,7 +44,7 @@ The default arguments used are }\if{html}{\out{}} } \examples{ -\dontshow{if (cards::is_pkg_installed("broom.helpers", reference_pkg = "cardx")) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +\dontshow{if (do.call(asNamespace("cardx")$is_pkg_installed, list(pkg = "broom.helpers", reference_pkg = "cardx"))) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} lm(AGE ~ ARM, data = cards::ADSL) |> ard_regression_basic() \dontshow{\}) # examplesIf} diff --git a/man/ard_smd_smd.Rd b/man/ard_smd_smd.Rd index 385cb01ed..27ffee4e4 100644 --- a/man/ard_smd_smd.Rd +++ b/man/ard_smd_smd.Rd @@ -34,7 +34,7 @@ ARD data frame Standardized mean difference calculated via \code{\link[smd:smd]{smd::smd()}} with \code{na.rm = TRUE}. } \examples{ -\dontshow{if (cards::is_pkg_installed("smd", reference_pkg = "cardx")) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +\dontshow{if (do.call(asNamespace("cardx")$is_pkg_installed, list(pkg = "smd", reference_pkg = "cardx"))) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} ard_smd_smd(cards::ADSL, by = ARM, variables = AGE, std.error = TRUE) ard_smd_smd(cards::ADSL, by = ARM, variables = AGEGR1, std.error = TRUE) \dontshow{\}) # examplesIf} diff --git a/man/ard_stats_anova.Rd b/man/ard_stats_anova.Rd index e3c058051..9e71a91df 100644 --- a/man/ard_stats_anova.Rd +++ b/man/ard_stats_anova.Rd @@ -73,7 +73,7 @@ e.g. \code{package = 'lme4'} must be specified when \code{fn = 'glmer'}. See example below. } \examples{ -\dontshow{if (cards::is_pkg_installed(c("broom", "withr", "lme4"), reference_pkg = "cardx")) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +\dontshow{if (do.call(asNamespace("cardx")$is_pkg_installed, list(pkg = c("broom", "withr", "lme4"), reference_pkg = "cardx"))) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} anova( lm(mpg ~ am, mtcars), lm(mpg ~ am + hp, mtcars) diff --git a/man/ard_stats_aov.Rd b/man/ard_stats_aov.Rd index 3731f0ccd..c38d1a37e 100644 --- a/man/ard_stats_aov.Rd +++ b/man/ard_stats_aov.Rd @@ -23,7 +23,7 @@ Analysis results data for Analysis of Variance. Calculated with \code{stats::aov()} } \examples{ -\dontshow{if (cards::is_pkg_installed(c("broom.helpers"), reference_pkg = "cardx")) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +\dontshow{if (do.call(asNamespace("cardx")$is_pkg_installed, list(pkg = "broom.helpers", reference_pkg = "cardx"))) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} ard_stats_aov(AGE ~ ARM, data = cards::ADSL) \dontshow{\}) # examplesIf} } diff --git a/man/ard_stats_chisq_test.Rd b/man/ard_stats_chisq_test.Rd index c820e8056..5dc96cb67 100644 --- a/man/ard_stats_chisq_test.Rd +++ b/man/ard_stats_chisq_test.Rd @@ -27,7 +27,7 @@ Analysis results data for Pearson's Chi-squared Test. Calculated with \code{chisq.test(x = data[[variable]], y = data[[by]], ...)} } \examples{ -\dontshow{if (cards::is_pkg_installed("broom", reference_pkg = "cardx")) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +\dontshow{if (do.call(asNamespace("cardx")$is_pkg_installed, list(pkg = "broom", reference_pkg = "cardx"))) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} cards::ADSL |> ard_stats_chisq_test(by = "ARM", variables = "AGEGR1") \dontshow{\}) # examplesIf} diff --git a/man/ard_stats_fisher_test.Rd b/man/ard_stats_fisher_test.Rd index 5ba78bbc8..1e07809b0 100644 --- a/man/ard_stats_fisher_test.Rd +++ b/man/ard_stats_fisher_test.Rd @@ -27,7 +27,7 @@ Analysis results data for Fisher's Exact Test. Calculated with \code{fisher.test(x = data[[variable]], y = data[[by]], ...)} } \examples{ -\dontshow{if (cards::is_pkg_installed("broom", reference_pkg = "cardx")) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +\dontshow{if (do.call(asNamespace("cardx")$is_pkg_installed, list(pkg = "broom", reference_pkg = "cardx"))) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} cards::ADSL[1:30, ] |> ard_stats_fisher_test(by = "ARM", variables = "AGEGR1") \dontshow{\}) # examplesIf} diff --git a/man/ard_stats_kruskal_test.Rd b/man/ard_stats_kruskal_test.Rd index 59e4bde5c..e9f4596cb 100644 --- a/man/ard_stats_kruskal_test.Rd +++ b/man/ard_stats_kruskal_test.Rd @@ -26,7 +26,7 @@ Analysis results data for Kruskal-Wallis Rank Sum Test. Calculated with \code{kruskal.test(data[[variable]], data[[by]], ...)} } \examples{ -\dontshow{if (cards::is_pkg_installed("broom", reference_pkg = "cardx")) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +\dontshow{if (do.call(asNamespace("cardx")$is_pkg_installed, list(pkg = "broom", reference_pkg = "cardx"))) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} cards::ADSL |> ard_stats_kruskal_test(by = "ARM", variables = "AGE") \dontshow{\}) # examplesIf} diff --git a/man/ard_stats_mcnemar_test.Rd b/man/ard_stats_mcnemar_test.Rd index 3b47a0498..0f1327b8b 100644 --- a/man/ard_stats_mcnemar_test.Rd +++ b/man/ard_stats_mcnemar_test.Rd @@ -31,7 +31,7 @@ The data is passed as \code{stats::mcnemar.test(x = data[[variable]], y = data[[ Please use \code{table(x = data[[variable]], y = data[[by]])} to check the contingency table. } \examples{ -\dontshow{if (cards::is_pkg_installed("broom", reference_pkg = "cardx")) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +\dontshow{if (do.call(asNamespace("cardx")$is_pkg_installed, list(pkg = "broom", reference_pkg = "cardx"))) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} cards::ADSL |> ard_stats_mcnemar_test(by = "SEX", variables = "EFFFL") \dontshow{\}) # examplesIf} diff --git a/man/ard_stats_mood_test.Rd b/man/ard_stats_mood_test.Rd index 902b54c0f..5a06c6c76 100644 --- a/man/ard_stats_mood_test.Rd +++ b/man/ard_stats_mood_test.Rd @@ -31,7 +31,7 @@ For the \code{ard_stats_mood_test()} function, the data is expected to be one ro The data is passed as \code{mood.test(data[[variable]] ~ data[[by]], ...)}. } \examples{ -\dontshow{if (cards::is_pkg_installed("broom", reference_pkg = "cardx")) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +\dontshow{if (do.call(asNamespace("cardx")$is_pkg_installed, list(pkg = "broom", reference_pkg = "cardx"))) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} cards::ADSL |> ard_stats_mood_test(by = "SEX", variables = "AGE") \dontshow{\}) # examplesIf} diff --git a/man/ard_stats_oneway_test.Rd b/man/ard_stats_oneway_test.Rd index 639c814f8..439fb9c3f 100644 --- a/man/ard_stats_oneway_test.Rd +++ b/man/ard_stats_oneway_test.Rd @@ -25,7 +25,7 @@ Analysis results data for Testing Equal Means in a One-Way Layout. calculated with \code{oneway.test()} } \examples{ -\dontshow{if (cards::is_pkg_installed(c("broom"), reference_pkg = "cardx")) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +\dontshow{if (do.call(asNamespace("cardx")$is_pkg_installed, list(pkg = "broom", reference_pkg = "cardx"))) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} ard_stats_oneway_test(AGE ~ ARM, data = cards::ADSL) \dontshow{\}) # examplesIf} } diff --git a/man/ard_stats_prop_test.Rd b/man/ard_stats_prop_test.Rd index 0dbfbfdc9..cb966e1c4 100644 --- a/man/ard_stats_prop_test.Rd +++ b/man/ard_stats_prop_test.Rd @@ -26,7 +26,7 @@ ARD data frame Analysis results data for a 2-sample test or proportions using \code{\link[stats:prop.test]{stats::prop.test()}}. } \examples{ -\dontshow{if (cards::is_pkg_installed("broom", reference_pkg = "cardx")) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +\dontshow{if (do.call(asNamespace("cardx")$is_pkg_installed, list(pkg = "broom", reference_pkg = "cardx"))) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} mtcars |> ard_stats_prop_test(by = vs, variables = am) \dontshow{\}) # examplesIf} diff --git a/man/ard_stats_t_test.Rd b/man/ard_stats_t_test.Rd index 5bc92322d..1bfb7fbe9 100644 --- a/man/ard_stats_t_test.Rd +++ b/man/ard_stats_t_test.Rd @@ -42,7 +42,7 @@ The data are then passed as \verb{t.test(x = data_wide[[]], y = data_wide[[]], paired = TRUE, ...)}. } \examples{ -\dontshow{if (cards::is_pkg_installed("broom", reference_pkg = "cardx")) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +\dontshow{if (do.call(asNamespace("cardx")$is_pkg_installed, list(pkg = "broom", reference_pkg = "cardx"))) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} cards::ADSL |> dplyr::filter(ARM \%in\% c("Placebo", "Xanomeline High Dose")) |> ard_stats_t_test(by = ARM, variables = c(AGE, BMIBL)) diff --git a/man/ard_stats_wilcox_test.Rd b/man/ard_stats_wilcox_test.Rd index 9f52f4f8d..14f48b213 100644 --- a/man/ard_stats_wilcox_test.Rd +++ b/man/ard_stats_wilcox_test.Rd @@ -42,7 +42,7 @@ The data are then passed as \verb{wilcox.test(x = data_wide[[]], y = data_wide[[]], paired = TRUE, ...)}. } \examples{ -\dontshow{if (cards::is_pkg_installed("broom", reference_pkg = "cardx")) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +\dontshow{if (do.call(asNamespace("cardx")$is_pkg_installed, list(pkg = "broom", reference_pkg = "cardx"))) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} cards::ADSL |> dplyr::filter(ARM \%in\% c("Placebo", "Xanomeline High Dose")) |> ard_stats_wilcox_test(by = "ARM", variables = "AGE") diff --git a/man/ard_survey_svychisq.Rd b/man/ard_survey_svychisq.Rd index 5b8465d2b..e645f5c00 100644 --- a/man/ard_survey_svychisq.Rd +++ b/man/ard_survey_svychisq.Rd @@ -32,7 +32,7 @@ Analysis results data for survey Chi-Square test using \code{\link[survey:svychi Only two-way comparisons are supported. } \examples{ -\dontshow{if (cards::is_pkg_installed(c("survey", "broom"), reference_pkg = "cardx")) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +\dontshow{if (do.call(asNamespace("cardx")$is_pkg_installed, list(pkg = c("survey", "broom"), reference_pkg = "cardx"))) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} data(api, package = "survey") dclus1 <- survey::svydesign(id = ~dnum, weights = ~pw, data = apiclus1, fpc = ~fpc) diff --git a/man/ard_survey_svycontinuous.Rd b/man/ard_survey_svycontinuous.Rd index c60b56add..8e5df93d2 100644 --- a/man/ard_survey_svycontinuous.Rd +++ b/man/ard_survey_svycontinuous.Rd @@ -56,7 +56,7 @@ where 'p##' is are the percentiles and \verb{##} is an integer between 0 and 100 } \examples{ -\dontshow{if (cards::is_pkg_installed("survey", reference_pkg = "cardx")) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +\dontshow{if (do.call(asNamespace("cardx")$is_pkg_installed, list(pkg = "survey", reference_pkg = "cardx"))) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} data(api, package = "survey") dclus1 <- survey::svydesign(id = ~dnum, weights = ~pw, data = apiclus1, fpc = ~fpc) diff --git a/man/ard_survey_svyranktest.Rd b/man/ard_survey_svyranktest.Rd index 33eea727c..e42c17620 100644 --- a/man/ard_survey_svyranktest.Rd +++ b/man/ard_survey_svyranktest.Rd @@ -29,7 +29,7 @@ ARD data frame Analysis results data for survey wilcox test using \code{\link[survey:svyranktest]{survey::svyranktest()}}. } \examples{ -\dontshow{if (cards::is_pkg_installed(c("survey", "broom"), reference_pkg = "cardx")) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +\dontshow{if (do.call(asNamespace("cardx")$is_pkg_installed, list(pkg = c("survey", "broom"), reference_pkg = "cardx"))) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} data(api, package = "survey") dclus2 <- survey::svydesign(id = ~ dnum + snum, fpc = ~ fpc1 + fpc2, data = apiclus2) diff --git a/man/ard_survey_svyttest.Rd b/man/ard_survey_svyttest.Rd index c80254245..b305f4912 100644 --- a/man/ard_survey_svyttest.Rd +++ b/man/ard_survey_svyttest.Rd @@ -29,7 +29,7 @@ ARD data frame Analysis results data for survey t-test using \code{\link[survey:svyttest]{survey::svyttest()}}. } \examples{ -\dontshow{if (cards::is_pkg_installed(c("survey", "broom"), reference_pkg = "cardx")) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +\dontshow{if (do.call(asNamespace("cardx")$is_pkg_installed, list(pkg = c("survey", "broom"), reference_pkg = "cardx"))) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} data(api, package = "survey") dclus2 <- survey::svydesign(id = ~ dnum + snum, fpc = ~ fpc1 + fpc2, data = apiclus2) diff --git a/man/ard_survival_survfit.Rd b/man/ard_survival_survfit.Rd index 93fb00cdc..0ea1ca8dd 100644 --- a/man/ard_survival_survfit.Rd +++ b/man/ard_survival_survfit.Rd @@ -41,7 +41,7 @@ survival fit model. } } \examples{ -\dontshow{if (cards::is_pkg_installed(c("survival", "broom"), reference_pkg = "cardx")) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +\dontshow{if (do.call(asNamespace("cardx")$is_pkg_installed, list(pkg = c("survival", "broom"), reference_pkg = "cardx"))) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} library(survival) survfit(Surv(AVAL, CNSR) ~ TRTA, cards::ADTTE) |> diff --git a/man/dot-paired_data_pivot_wider.Rd b/man/dot-paired_data_pivot_wider.Rd index 4de078355..e51632add 100644 --- a/man/dot-paired_data_pivot_wider.Rd +++ b/man/dot-paired_data_pivot_wider.Rd @@ -1,12 +1,10 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/ard_stats_t_test.R, R/ard_stats_wilcox_test.R +% Please edit documentation in R/ard_stats_t_test.R \name{.paired_data_pivot_wider} \alias{.paired_data_pivot_wider} \title{Convert long paired data to wide} \usage{ -.paired_data_pivot_wider(data, by, variable, id, env = rlang::caller_env()) - -.paired_data_pivot_wider(data, by, variable, id, env = rlang::caller_env()) +.paired_data_pivot_wider(data, by, variable, id) } \arguments{ \item{data}{(\code{data.frame})\cr a data frame that is one line per subject per group} @@ -16,25 +14,14 @@ \item{variable}{(\code{string})\cr variable column name} \item{id}{(\code{string})\cr subject id column name} - -\item{env}{(\code{environment}) used for error messaging. Default is \code{rlang::caller_env()}} } \value{ -a wide data frame - a wide data frame } \description{ -Convert long paired data to wide - Convert long paired data to wide } \examples{ -cards::ADSL[c("ARM", "AGE")] |> - dplyr::filter(ARM \%in\% c("Placebo", "Xanomeline High Dose")) |> - dplyr::mutate(.by = ARM, USUBJID = dplyr::row_number()) |> - dplyr::arrange(USUBJID, ARM) |> - cardx:::.paired_data_pivot_wider(by = "ARM", variable = "AGE", id = "USUBJID") cards::ADSL[c("ARM", "AGE")] |> dplyr::filter(ARM \%in\% c("Placebo", "Xanomeline High Dose")) |> dplyr::mutate(.by = ARM, USUBJID = dplyr::row_number()) |> diff --git a/man/proportion_ci.Rd b/man/proportion_ci.Rd index 888eee456..8094fc047 100644 --- a/man/proportion_ci.Rd +++ b/man/proportion_ci.Rd @@ -101,7 +101,7 @@ z_{\alpha/2} \sqrt{\frac{\hat{p}_j(1 - \hat{p}_j)}{n_j} + }} \examples{ -\dontshow{if (cards::is_pkg_installed("broom", reference_pkg = "cardx")) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +\dontshow{if (do.call(asNamespace("cardx")$is_pkg_installed, list(pkg = "broom", reference_pkg = "cardx"))) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} x <- c( TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE diff --git a/tests/testthat/_snaps/ard_vif.md b/tests/testthat/_snaps/ard_car_vif.md similarity index 77% rename from tests/testthat/_snaps/ard_vif.md rename to tests/testthat/_snaps/ard_car_vif.md index 2fef8dd36..745c24ef3 100644 --- a/tests/testthat/_snaps/ard_vif.md +++ b/tests/testthat/_snaps/ard_car_vif.md @@ -1,7 +1,7 @@ -# ard_vif() works +# ard_car_vif() works Code - as.data.frame(ard_vif(lm(AGE ~ ARM + SEX, data = cards::ADSL))) + as.data.frame(ard_car_vif(lm(AGE ~ ARM + SEX, data = cards::ADSL))) Output variable context stat_name stat_label stat fmt_fn warning error 1 ARM vif GVIF GVIF 1.015675 1 NULL NULL @@ -14,16 +14,16 @@ --- Code - as.data.frame(ard_vif(lm(AGE ~ BMIBL + EDUCLVL, data = cards::ADSL))) + as.data.frame(ard_car_vif(lm(AGE ~ BMIBL + EDUCLVL, data = cards::ADSL))) Output variable context stat_name stat_label stat fmt_fn warning error 1 BMIBL vif VIF VIF 1.010522 1 NULL NULL 2 EDUCLVL vif VIF VIF 1.010522 1 NULL NULL -# ard_vif() appropriate errors are given for model with only 1 term +# ard_car_vif() appropriate errors are given for model with only 1 term Code - as.data.frame(ard_vif(lm(AGE ~ ARM, data = cards::ADSL))) + as.data.frame(ard_car_vif(lm(AGE ~ ARM, data = cards::ADSL))) Output variable context stat_name stat_label stat fmt_fn warning 1 ARM vif VIF VIF NULL NULL NULL @@ -42,6 +42,5 @@ ard_vif(cards::ADSL) Condition Error in `ard_vif()`: - ! There was an error running `car::vif()`. See below. - x no applicable method for 'vcov' applied to an object of class "c('tbl_df', 'tbl', 'data.frame')" + ! could not find function "ard_vif" diff --git a/tests/testthat/_snaps/ard_stats_chisq_test.md b/tests/testthat/_snaps/ard_stats_chisq_test.md new file mode 100644 index 000000000..c5ad14cf0 --- /dev/null +++ b/tests/testthat/_snaps/ard_stats_chisq_test.md @@ -0,0 +1,17 @@ +# shuffle_ard fills missing group levels if the group is meaningful + + Code + as.data.frame(cards::shuffle_ard(cards::bind_ard(ard_stats_chisq_test(data = adsl_sub, + by = "ARM", variables = "AGEGR1"), ard_stats_chisq_test(data = adsl_sub, by = "SEX", + variables = "AGEGR1")))) + Output + ARM SEX variable context stat_name stat + 1 Overall ARM AGEGR1 chisqtest statistic 5.079442e+00 + 2 Overall ARM AGEGR1 chisqtest p.value 7.888842e-02 + 3 Overall ARM AGEGR1 chisqtest parameter 2.000000e+00 + 4 Overall ARM AGEGR1 chisqtest B 2.000000e+03 + 5 Overall SEX AGEGR1 chisqtest statistic 1.039442e+00 + 6 Overall SEX AGEGR1 chisqtest p.value 5.946864e-01 + 7 Overall SEX AGEGR1 chisqtest parameter 2.000000e+00 + 8 Overall SEX AGEGR1 chisqtest B 2.000000e+03 + diff --git a/tests/testthat/_snaps/ard_moodtest.md b/tests/testthat/_snaps/ard_stats_mood_test.md similarity index 85% rename from tests/testthat/_snaps/ard_moodtest.md rename to tests/testthat/_snaps/ard_stats_mood_test.md index b6bb0e8c2..8e5db79df 100644 --- a/tests/testthat/_snaps/ard_moodtest.md +++ b/tests/testthat/_snaps/ard_stats_mood_test.md @@ -1,7 +1,7 @@ -# ard_moodtest() works +# ard_stats_mood_test() works Code - as.data.frame(ard_moodtest(cards::ADSL, by = SEX, variable = AGE)) + as.data.frame(ard_stats_mood_test(cards::ADSL, by = SEX, variable = AGE)) Output group1 variable context stat_name stat_label 1 SEX AGE moodtest statistic Z-Statistic diff --git a/tests/testthat/_snaps/ard_onewaytest.md b/tests/testthat/_snaps/ard_stats_oneway_test.md similarity index 68% rename from tests/testthat/_snaps/ard_onewaytest.md rename to tests/testthat/_snaps/ard_stats_oneway_test.md index 616b24342..6a597b9d2 100644 --- a/tests/testthat/_snaps/ard_onewaytest.md +++ b/tests/testthat/_snaps/ard_stats_oneway_test.md @@ -1,7 +1,7 @@ -# ard_onewaytest() works +# ard_stats_oneway_test() works Code - head(dplyr::select(ard_onewaytest(AGEGR1 ~ ARM, data = cards::ADSL), c( + head(dplyr::select(ard_stats_oneway_test(AGEGR1 ~ ARM, data = cards::ADSL), c( "stat_name", "stat", "warning")), 3) Message {cards} data frame: 3 x 3 diff --git a/tests/testthat/_snaps/ard_svychisq.md b/tests/testthat/_snaps/ard_survey_svychisq.md similarity index 76% rename from tests/testthat/_snaps/ard_svychisq.md rename to tests/testthat/_snaps/ard_survey_svychisq.md index 46f7f46df..5d9b016f3 100644 --- a/tests/testthat/_snaps/ard_svychisq.md +++ b/tests/testthat/_snaps/ard_survey_svychisq.md @@ -1,9 +1,9 @@ -# ard_svychisq() works +# ard_survey_svychisq() works Code - as.data.frame(dplyr::slice_head(dplyr::group_by(dplyr::select(ard_svychisq( - dclus2, variables = c(sch.wide, stype), by = comp.imp, statistic = "adjWald"), - c(1:3, 5:6)), variable), n = 3)) + as.data.frame(dplyr::slice_head(dplyr::group_by(dplyr::select( + ard_survey_svychisq(dclus2, variables = c(sch.wide, stype), by = comp.imp, + statistic = "adjWald"), c(1:3, 5:6)), variable), n = 3)) Output group1 variable context stat_label stat 1 comp.imp sch.wide svychisq Nominator Degrees of Freedom 1 diff --git a/tests/testthat/_snaps/ard_svyranktest.md b/tests/testthat/_snaps/ard_survey_svyranktest.md similarity index 98% rename from tests/testthat/_snaps/ard_svyranktest.md rename to tests/testthat/_snaps/ard_survey_svyranktest.md index 97d6b33eb..85ba37bb8 100644 --- a/tests/testthat/_snaps/ard_svyranktest.md +++ b/tests/testthat/_snaps/ard_survey_svyranktest.md @@ -1,4 +1,4 @@ -# ard_svyranktest() works +# ard_survey_svyranktest() works Code dplyr::select(as.data.frame(svyranktest[[1]]), stat_label, stat) diff --git a/tests/testthat/_snaps/ard_survfit.md b/tests/testthat/_snaps/ard_survival_survfit.md similarity index 79% rename from tests/testthat/_snaps/ard_survfit.md rename to tests/testthat/_snaps/ard_survival_survfit.md index 5d209bb98..da830d66d 100644 --- a/tests/testthat/_snaps/ard_survfit.md +++ b/tests/testthat/_snaps/ard_survival_survfit.md @@ -1,9 +1,9 @@ -# ard_survfit() works with times provided +# ard_survival_survfit() works with times provided Code - print(dplyr::mutate(ard_survfit(survival::survfit(survival::Surv(AVAL, CNSR) ~ - TRTA, cards::ADTTE), times = c(60, 180)), stat = lapply(stat, function(x) - ifelse(is.numeric(x), cards::round5(x, 3), x))), n = Inf) + print(dplyr::mutate(ard_survival_survfit(survival::survfit(survival::Surv(AVAL, + CNSR) ~ TRTA, cards::ADTTE), times = c(60, 180)), stat = lapply(stat, + function(x) ifelse(is.numeric(x), cards::round5(x, 3), x))), n = Inf) Message {cards} data frame: 18 x 11 Output @@ -29,12 +29,12 @@ Message i 4 more variables: context, fmt_fn, warning, error -# ard_survfit() works with different type +# ard_survival_survfit() works with different type Code - print(dplyr::mutate(ard_survfit(survival::survfit(survival::Surv(AVAL, CNSR) ~ - TRTA, cards::ADTTE), times = c(60, 180), type = "risk"), stat = lapply(stat, - function(x) ifelse(is.numeric(x), cards::round5(x, 3), x))), n = Inf) + print(dplyr::mutate(ard_survival_survfit(survival::survfit(survival::Surv(AVAL, + CNSR) ~ TRTA, cards::ADTTE), times = c(60, 180), type = "risk"), stat = lapply( + stat, function(x) ifelse(is.numeric(x), cards::round5(x, 3), x))), n = Inf) Message {cards} data frame: 18 x 11 Output @@ -60,12 +60,12 @@ Message i 4 more variables: context, fmt_fn, warning, error -# ard_survfit() works with probs provided +# ard_survival_survfit() works with probs provided Code - print(dplyr::mutate(ard_survfit(survival::survfit(survival::Surv(AVAL, CNSR) ~ - TRTA, cards::ADTTE), probs = c(0.25, 0.75)), stat = lapply(stat, function(x) - ifelse(is.numeric(x), cards::round5(x, 3), x))), n = Inf) + print(dplyr::mutate(ard_survival_survfit(survival::survfit(survival::Surv(AVAL, + CNSR) ~ TRTA, cards::ADTTE), probs = c(0.25, 0.75)), stat = lapply(stat, + function(x) ifelse(is.numeric(x), cards::round5(x, 3), x))), n = Inf) Message {cards} data frame: 18 x 11 Output @@ -91,12 +91,12 @@ Message i 4 more variables: context, fmt_fn, warning, error -# ard_survfit() works with unstratified model +# ard_survival_survfit() works with unstratified model Code - print(dplyr::mutate(ard_survfit(survival::survfit(survival::Surv(time, status) ~ - 1, data = survival::lung), times = c(60, 180)), stat = lapply(stat, function( - x) ifelse(is.numeric(x), cards::round5(x, 3), x))), n = Inf) + print(dplyr::mutate(ard_survival_survfit(survival::survfit(survival::Surv(time, + status) ~ 1, data = survival::lung), times = c(60, 180)), stat = lapply(stat, + function(x) ifelse(is.numeric(x), cards::round5(x, 3), x))), n = Inf) Message {cards} data frame: 6 x 9 Output @@ -113,9 +113,9 @@ --- Code - print(dplyr::mutate(ard_survfit(survival::survfit(survival::Surv(time, status) ~ - 1, data = survival::lung), probs = c(0.5, 0.75)), stat = lapply(stat, - function(x) ifelse(is.numeric(x), cards::round5(x, 3), x))), n = Inf) + print(dplyr::mutate(ard_survival_survfit(survival::survfit(survival::Surv(time, + status) ~ 1, data = survival::lung), probs = c(0.5, 0.75)), stat = lapply( + stat, function(x) ifelse(is.numeric(x), cards::round5(x, 3), x))), n = Inf) Message {cards} data frame: 6 x 9 Output @@ -129,13 +129,13 @@ Message i 3 more variables: fmt_fn, warning, error -# ard_survfit() works with multiple stratification variables +# ard_survival_survfit() works with multiple stratification variables Code - print(head(dplyr::select(dplyr::mutate(ard_survfit(survival::survfit(survival::Surv( - time, status) ~ sex + ph.ecog, data = survival::lung), times = c(60, 180)), - stat = lapply(stat, function(x) ifelse(is.numeric(x), cards::round5(x, 3), x))), - "group1", "group1_level", "group2", "group2_level"), 20), n = Inf) + print(head(dplyr::select(dplyr::mutate(ard_survival_survfit(survival::survfit( + survival::Surv(time, status) ~ sex + ph.ecog, data = survival::lung), times = c( + 60, 180)), stat = lapply(stat, function(x) ifelse(is.numeric(x), cards::round5( + x, 3), x))), "group1", "group1_level", "group2", "group2_level"), 20), n = Inf) Message {cards} data frame: 20 x 4 Output @@ -164,10 +164,10 @@ --- Code - print(head(dplyr::select(dplyr::mutate(ard_survfit(survival::survfit(survival::Surv( - time, status) ~ sex + ph.ecog, data = survival::lung), probs = c(0.5, 0.75)), - stat = lapply(stat, function(x) ifelse(is.numeric(x), cards::round5(x, 3), x))), - "group1", "group1_level", "group2", "group2_level"), 20), n = Inf) + print(head(dplyr::select(dplyr::mutate(ard_survival_survfit(survival::survfit( + survival::Surv(time, status) ~ sex + ph.ecog, data = survival::lung), probs = c( + 0.5, 0.75)), stat = lapply(stat, function(x) ifelse(is.numeric(x), cards::round5( + x, 3), x))), "group1", "group1_level", "group2", "group2_level"), 20), n = Inf) Message {cards} data frame: 20 x 4 Output @@ -193,12 +193,12 @@ 19 sex 1 ph.ecog 3 20 sex 1 ph.ecog 3 -# ard_survfit() works with competing risks +# ard_survival_survfit() works with competing risks Code print(dplyr::mutate(survival::survfit(survival::Surv(AVAL, CNSR) ~ TRTA, data = ADTTE_MS) %>% - ard_survfit(times = c(60, 180)), stat = lapply(stat, function(x) ifelse( - is.numeric(x), cards::round5(x, 3), x))), n = Inf) + ard_survival_survfit(times = c(60, 180)), stat = lapply(stat, function(x) + ifelse(is.numeric(x), cards::round5(x, 3), x))), n = Inf) Message Multi-state model detected. Showing probabilities into state 'death from cancer'. {cards} data frame: 18 x 11 @@ -225,37 +225,38 @@ Message i 4 more variables: context, fmt_fn, warning, error -# ard_survfit() errors are properly handled +# ard_survival_survfit() errors are properly handled Code - ard_survfit("not_survfit") + ard_survival_survfit("not_survfit") Condition - Error in `ard_survfit()`: + Error in `ard_survival_survfit()`: ! The `x` argument must be class , not a string. --- Code - ard_survfit(survival::survfit(survival::Surv(AVAL, CNSR) ~ TRTA, cards::ADTTE), - times = 100, type = "notatype") + ard_survival_survfit(survival::survfit(survival::Surv(AVAL, CNSR) ~ TRTA, + cards::ADTTE), times = 100, type = "notatype") Condition - Error in `ard_survfit()`: + Error in `ard_survival_survfit()`: ! `type` must be one of "survival", "risk", or "cumhaz", not "notatype". --- Code - ard_survfit(survival::survfit(survival::Surv(AVAL, CNSR) ~ TRTA, cards::ADTTE), - times = 100, probs = c(0.25, 0.75)) + ard_survival_survfit(survival::survfit(survival::Surv(AVAL, CNSR) ~ TRTA, + cards::ADTTE), times = 100, probs = c(0.25, 0.75)) Condition - Error in `ard_survfit()`: + Error in `ard_survival_survfit()`: ! One and only one of `times` and `probs` must be specified. -# ard_survfit() errors with stratified Cox model +# ard_survival_survfit() errors with stratified Cox model Code - ard_survfit(survfit(coxph(Surv(time, status) ~ age + strata(sex), survival::lung))) + ard_survival_survfit(survfit(coxph(Surv(time, status) ~ age + strata(sex), + survival::lung))) Condition - Error in `ard_survfit()`: + Error in `ard_survival_survfit()`: ! Argument `x` cannot be class . diff --git a/tests/testthat/_snaps/ard_svycontinuous.md b/tests/testthat/_snaps/ard_svycontinuous.md deleted file mode 100644 index 28d83bb09..000000000 --- a/tests/testthat/_snaps/ard_svycontinuous.md +++ /dev/null @@ -1,54 +0,0 @@ -# unstratified ard_svycontinuous() works - - Code - ard_uni_svy_cont - Message - {cards} data frame: 10 x 8 - Output - variable context stat_name stat_label stat fmt_fn - 1 api00 continuo… mean Mean 644.169 1 - 2 api00 continuo… median Median 652 1 - 3 api00 continuo… min Minimum 411 1 - 4 api00 continuo… max Maximum 905 1 - 5 api00 continuo… sum Sum 3989985 1 - 6 api00 continuo… var Variance 11182.82 1 - 7 api00 continuo… sd Standard… 105.749 1 - 8 api00 continuo… mean.std.error SE(Mean) 23.542 1 - 9 api00 continuo… deff Design E… 9.346 1 - 10 api00 continuo… p75 75% Perc… 719 1 - Message - i 2 more variables: warning, error - -# ard_svycontinuous(fmt_fn) - - Code - ard_svycontinuous(dclus1, variables = api00, statistic = ~ c("mean", "median", - "min", "max"), fmt_fn = list(api00 = list(mean = 2, median = "xx.xx", min = as.character))) - Message - {cards} data frame: 4 x 8 - Output - variable context stat_name stat_label stat fmt_fn - 1 api00 continuo… mean Mean 644.169 2 - 2 api00 continuo… median Median 652 xx.xx - 3 api00 continuo… min Minimum 411 - 4 api00 continuo… max Maximum 905 1 - Message - i 2 more variables: warning, error - -# ard_svycontinuous(stat_label) - - Code - ard_svycontinuous(dclus1, variables = api00, statistic = ~ c("mean", "median", - "min", "max"), stat_label = list(api00 = list(mean = "MeAn", median = "MEDian", - min = "MINimum"))) - Message - {cards} data frame: 4 x 8 - Output - variable context stat_name stat_label stat fmt_fn - 1 api00 continuo… mean MeAn 644.169 1 - 2 api00 continuo… median MEDian 652 1 - 3 api00 continuo… min MINimum 411 1 - 4 api00 continuo… max Maximum 905 1 - Message - i 2 more variables: warning, error - diff --git a/tests/testthat/_snaps/ard_ttest.md b/tests/testthat/_snaps/ard_ttest.md deleted file mode 100644 index 9fc30da10..000000000 --- a/tests/testthat/_snaps/ard_ttest.md +++ /dev/null @@ -1,73 +0,0 @@ -# ard_ttest() works - - Code - as.data.frame(ard_ttest(cards::ADSL, by = ARM, variable = AGE, var.equal = TRUE)) - Output - group1 variable context stat_name stat_label stat fmt_fn warning - 1 ARM AGE ttest estimate Mean Difference NULL NULL NULL - 2 ARM AGE ttest estimate1 Group 1 Mean NULL NULL NULL - 3 ARM AGE ttest estimate2 Group 2 Mean NULL NULL NULL - 4 ARM AGE ttest statistic t Statistic NULL NULL NULL - 5 ARM AGE ttest p.value p-value NULL NULL NULL - 6 ARM AGE ttest parameter Degrees of Freedom NULL NULL NULL - 7 ARM AGE ttest conf.low CI Lower Bound NULL NULL NULL - 8 ARM AGE ttest conf.high CI Upper Bound NULL NULL NULL - 9 ARM AGE ttest method method NULL NULL NULL - 10 ARM AGE ttest alternative alternative NULL NULL NULL - 11 ARM AGE ttest mu H0 Mean 0 1 NULL - 12 ARM AGE ttest paired Paired t-test FALSE NULL NULL - 13 ARM AGE ttest var.equal Equal Variances TRUE NULL NULL - 14 ARM AGE ttest conf.level CI Confidence Level 0.95 1 NULL - error - 1 grouping factor must have exactly 2 levels - 2 grouping factor must have exactly 2 levels - 3 grouping factor must have exactly 2 levels - 4 grouping factor must have exactly 2 levels - 5 grouping factor must have exactly 2 levels - 6 grouping factor must have exactly 2 levels - 7 grouping factor must have exactly 2 levels - 8 grouping factor must have exactly 2 levels - 9 grouping factor must have exactly 2 levels - 10 grouping factor must have exactly 2 levels - 11 grouping factor must have exactly 2 levels - 12 grouping factor must have exactly 2 levels - 13 grouping factor must have exactly 2 levels - 14 grouping factor must have exactly 2 levels - -# ard_paired_ttest() works - - Code - as.data.frame(ard_paired_ttest(dplyr::mutate(ADSL_paired, ARM = ifelse(dplyr::row_number() == - 1L, "3rd ARM", ARM)), by = ARM, variable = AGE, id = USUBJID, var.equal = TRUE)) - Output - group1 variable context stat_name stat_label stat fmt_fn warning - 1 ARM AGE ttest estimate Mean Difference NULL NULL NULL - 2 ARM AGE ttest estimate1 Group 1 Mean NULL NULL NULL - 3 ARM AGE ttest estimate2 Group 2 Mean NULL NULL NULL - 4 ARM AGE ttest statistic t Statistic NULL NULL NULL - 5 ARM AGE ttest p.value p-value NULL NULL NULL - 6 ARM AGE ttest parameter Degrees of Freedom NULL NULL NULL - 7 ARM AGE ttest conf.low CI Lower Bound NULL NULL NULL - 8 ARM AGE ttest conf.high CI Upper Bound NULL NULL NULL - 9 ARM AGE ttest method method NULL NULL NULL - 10 ARM AGE ttest alternative alternative NULL NULL NULL - 11 ARM AGE ttest mu H0 Mean 0 1 NULL - 12 ARM AGE ttest paired Paired t-test TRUE NULL NULL - 13 ARM AGE ttest var.equal Equal Variances TRUE NULL NULL - 14 ARM AGE ttest conf.level CI Confidence Level 0.95 1 NULL - error - 1 The `by` argument must have two and only two levels. - 2 The `by` argument must have two and only two levels. - 3 The `by` argument must have two and only two levels. - 4 The `by` argument must have two and only two levels. - 5 The `by` argument must have two and only two levels. - 6 The `by` argument must have two and only two levels. - 7 The `by` argument must have two and only two levels. - 8 The `by` argument must have two and only two levels. - 9 The `by` argument must have two and only two levels. - 10 The `by` argument must have two and only two levels. - 11 The `by` argument must have two and only two levels. - 12 The `by` argument must have two and only two levels. - 13 The `by` argument must have two and only two levels. - 14 The `by` argument must have two and only two levels. - diff --git a/tests/testthat/test-ard_aod_wald_test.R b/tests/testthat/test-ard_aod_wald_test.R index 3f149b76f..3576c62bc 100644 --- a/tests/testthat/test-ard_aod_wald_test.R +++ b/tests/testthat/test-ard_aod_wald_test.R @@ -1,3 +1,5 @@ +skip_if_not(do.call(asNamespace("cardx")$is_pkg_installed, list(pkg = "aod", reference_pkg = "cardx"))) + test_that("ard_aod_wald_test() works", { # works for a generic case expect_error( diff --git a/tests/testthat/test-ard_car_anova.R b/tests/testthat/test-ard_car_anova.R index b7d642750..5468f15fb 100644 --- a/tests/testthat/test-ard_car_anova.R +++ b/tests/testthat/test-ard_car_anova.R @@ -1,4 +1,6 @@ -skip_if_not(cards::is_pkg_installed(c("broom.helpers", "car"), reference_pkg = "cardx")) +skip_if_not( + do.call(asNamespace("cardx")$is_pkg_installed, list(pkg = c("broom.helpers", "car"), reference_pkg = "cardx")) +) test_that("ard_car_anova() works", { # works for a generic case diff --git a/tests/testthat/test-ard_car_vif.R b/tests/testthat/test-ard_car_vif.R index 6d717b8a3..390fdb77f 100644 --- a/tests/testthat/test-ard_car_vif.R +++ b/tests/testthat/test-ard_car_vif.R @@ -1,3 +1,5 @@ +skip_if_not(is_pkg_installed("car", reference_pkg = "cardx")) + test_that("ard_car_vif() works", { expect_snapshot( lm(AGE ~ ARM + SEX, data = cards::ADSL) |> diff --git a/tests/testthat/test-ard_effectsize_cohens_d.R b/tests/testthat/test-ard_effectsize_cohens_d.R index 25a83bc5b..fe5c771bf 100644 --- a/tests/testthat/test-ard_effectsize_cohens_d.R +++ b/tests/testthat/test-ard_effectsize_cohens_d.R @@ -1,4 +1,4 @@ -skip_if_not(cards::is_pkg_installed(c("effectsize", "parameters"), reference_pkg = "cardx")) +skip_if_not(is_pkg_installed(c("effectsize", "parameters"), reference_pkg = "cardx")) test_that("ard_effectsize_cohens_d() works", { # there were some discrepancies in the 7th decimal place on one system diff --git a/tests/testthat/test-ard_effectsize_hedges_g.R b/tests/testthat/test-ard_effectsize_hedges_g.R index f2e0dee97..47f84ed93 100644 --- a/tests/testthat/test-ard_effectsize_hedges_g.R +++ b/tests/testthat/test-ard_effectsize_hedges_g.R @@ -1,4 +1,4 @@ -skip_if_not(cards::is_pkg_installed(c("effectsize", "parameters", "withr"), reference_pkg = "cardx")) +skip_if_not(is_pkg_installed(c("effectsize", "parameters", "withr"), reference_pkg = "cardx")) test_that("ard_effectsize_hedges_g() works", { withr::local_namespace("effectsize") diff --git a/tests/testthat/test-ard_proportion_ci.R b/tests/testthat/test-ard_proportion_ci.R index 58201779d..6f7ceb9b7 100644 --- a/tests/testthat/test-ard_proportion_ci.R +++ b/tests/testthat/test-ard_proportion_ci.R @@ -1,4 +1,4 @@ -skip_if_not(cards::is_pkg_installed("broom", reference_pkg = "cardx")) +skip_if_not(do.call(asNamespace("cardx")$is_pkg_installed, list(pkg = "broom", reference_pkg = "cardx"))) test_that("ard_proportion_ci() works", { # testing the easy methods together diff --git a/tests/testthat/test-ard_regression.R b/tests/testthat/test-ard_regression.R index 3aa62f7c4..6fec0806e 100644 --- a/tests/testthat/test-ard_regression.R +++ b/tests/testthat/test-ard_regression.R @@ -1,4 +1,4 @@ -skip_if_not(cards::is_pkg_installed("broom.helpers", reference_pkg = "cardx")) +skip_if_not(do.call(asNamespace("cardx")$is_pkg_installed, list(pkg = "broom.helpers", reference_pkg = "cardx"))) test_that("ard_regression() works", { expect_snapshot( diff --git a/tests/testthat/test-ard_regression_basic.R b/tests/testthat/test-ard_regression_basic.R index a97f89f9d..93932b563 100644 --- a/tests/testthat/test-ard_regression_basic.R +++ b/tests/testthat/test-ard_regression_basic.R @@ -1,4 +1,4 @@ -skip_if_not(cards::is_pkg_installed("broom.helpers", reference_pkg = "cardx")) +skip_if_not(do.call(asNamespace("cardx")$is_pkg_installed, list(pkg = "broom.helpers", reference_pkg = "cardx"))) test_that("ard_regression_basic() works", { expect_error( diff --git a/tests/testthat/test-ard_smd_smd.R b/tests/testthat/test-ard_smd_smd.R index 5c0fc2f86..02a2d4523 100644 --- a/tests/testthat/test-ard_smd_smd.R +++ b/tests/testthat/test-ard_smd_smd.R @@ -1,4 +1,4 @@ -skip_if_not(cards::is_pkg_installed("smd", reference_pkg = "cardx")) +skip_if_not(is_pkg_installed("smd", reference_pkg = "cardx")) test_that("ard_smd_smd() works", { expect_error( @@ -30,7 +30,8 @@ test_that("ard_smd_smd() works", { }) test_that("ard_smd() works with survey data", { - skip_if_not(cards::is_pkg_installed("survey", reference_pkg = "cardx")) + skip_if_not(is_pkg_installed("survey", reference_pkg = "cardx")) + data(api, package = "survey") dclus1 <- survey::svydesign(id = ~dnum, weights = ~pw, data = apiclus1, fpc = ~fpc) diff --git a/tests/testthat/test-ard_stats_anova.R b/tests/testthat/test-ard_stats_anova.R index 1982d7b3f..b2be9a90b 100644 --- a/tests/testthat/test-ard_stats_anova.R +++ b/tests/testthat/test-ard_stats_anova.R @@ -1,4 +1,4 @@ -skip_if_not(cards::is_pkg_installed(c("broom", "withr", "lme4", "survival"), reference_pkg = "cardx")) +skip_if_not(is_pkg_installed(c("broom", "withr", "lme4", "survival"), reference_pkg = "cardx")) test_that("ard_stats_anova.anova() works", { expect_equal( diff --git a/tests/testthat/test-ard_stats_aov.R b/tests/testthat/test-ard_stats_aov.R index 99fe86831..01de036ce 100644 --- a/tests/testthat/test-ard_stats_aov.R +++ b/tests/testthat/test-ard_stats_aov.R @@ -1,4 +1,4 @@ -skip_if_not(cards::is_pkg_installed("broom.helpers", reference_pkg = "cardx")) +skip_if_not(is_pkg_installed("broom.helpers", reference_pkg = "cardx")) test_that("ard_aov() works", { expect_error( diff --git a/tests/testthat/test-ard_stats_chisq_test.R b/tests/testthat/test-ard_stats_chisq_test.R index 37b3ef879..0e99d39aa 100644 --- a/tests/testthat/test-ard_stats_chisq_test.R +++ b/tests/testthat/test-ard_stats_chisq_test.R @@ -1,4 +1,4 @@ -skip_if_not(cards::is_pkg_installed("broom", reference_pkg = "cardx")) +skip_if_not(is_pkg_installed("broom", reference_pkg = "cardx")) test_that("ard_stats_chisq_test() works", { expect_error( diff --git a/tests/testthat/test-ard_stats_fisher_test.R b/tests/testthat/test-ard_stats_fisher_test.R index 92731eaf4..eb7d2033c 100644 --- a/tests/testthat/test-ard_stats_fisher_test.R +++ b/tests/testthat/test-ard_stats_fisher_test.R @@ -1,4 +1,4 @@ -skip_if_not(cards::is_pkg_installed("broom", reference_pkg = "cardx")) +skip_if_not(is_pkg_installed("broom", reference_pkg = "cardx")) test_that("ard_stats_fisher_test() works", { expect_error( diff --git a/tests/testthat/test-ard_stats_kruskal_test.R b/tests/testthat/test-ard_stats_kruskal_test.R index cdf1f023d..fb4e96bdb 100644 --- a/tests/testthat/test-ard_stats_kruskal_test.R +++ b/tests/testthat/test-ard_stats_kruskal_test.R @@ -1,4 +1,4 @@ -skip_if_not(cards::is_pkg_installed("broom", reference_pkg = "cardx")) +skip_if_not(is_pkg_installed("broom", reference_pkg = "cardx")) test_that("ard_stats_kruskal_test() works", { expect_error( diff --git a/tests/testthat/test-ard_stats_mcnemar_test.R b/tests/testthat/test-ard_stats_mcnemar_test.R index 8f757cab2..5b54f50fa 100644 --- a/tests/testthat/test-ard_stats_mcnemar_test.R +++ b/tests/testthat/test-ard_stats_mcnemar_test.R @@ -1,4 +1,4 @@ -skip_if_not(cards::is_pkg_installed("broom", reference_pkg = "cardx")) +skip_if_not(is_pkg_installed("broom", reference_pkg = "cardx")) test_that("ard_stats_mcnemar_test() works", { expect_error( diff --git a/tests/testthat/test-ard_stats_mood_test.R b/tests/testthat/test-ard_stats_mood_test.R index 34f12a0c4..292399b4c 100644 --- a/tests/testthat/test-ard_stats_mood_test.R +++ b/tests/testthat/test-ard_stats_mood_test.R @@ -1,4 +1,4 @@ -skip_if_not(cards::is_pkg_installed("broom", reference_pkg = "cardx")) +skip_if_not(is_pkg_installed("broom", reference_pkg = "cardx")) test_that("ard_stats_mood_test() works", { expect_error( diff --git a/tests/testthat/test-ard_stats_oneway_test.R b/tests/testthat/test-ard_stats_oneway_test.R index 2182287bc..55edb7a07 100644 --- a/tests/testthat/test-ard_stats_oneway_test.R +++ b/tests/testthat/test-ard_stats_oneway_test.R @@ -1,4 +1,4 @@ -skip_if_not(cards::is_pkg_installed("broom", reference_pkg = "cardx")) +skip_if_not(is_pkg_installed("broom", reference_pkg = "cardx")) test_that("ard_stats_oneway_test() works", { expect_error( diff --git a/tests/testthat/test-ard_stats_prop_test.R b/tests/testthat/test-ard_stats_prop_test.R index 7ef180624..51b74adf6 100644 --- a/tests/testthat/test-ard_stats_prop_test.R +++ b/tests/testthat/test-ard_stats_prop_test.R @@ -1,4 +1,4 @@ -skip_if_not(cards::is_pkg_installed("broom", reference_pkg = "cardx")) +skip_if_not(is_pkg_installed("broom", reference_pkg = "cardx")) test_that("ard_stats_prop_test() works", { expect_error( diff --git a/tests/testthat/test-ard_stats_t_test.R b/tests/testthat/test-ard_stats_t_test.R index 600ec68d7..15bb29a2d 100644 --- a/tests/testthat/test-ard_stats_t_test.R +++ b/tests/testthat/test-ard_stats_t_test.R @@ -1,4 +1,4 @@ -skip_if_not(cards::is_pkg_installed("broom", reference_pkg = "cardx")) +skip_if_not(is_pkg_installed("broom", reference_pkg = "cardx")) test_that("ard_stats_t_test() works", { # One Sample t-test works diff --git a/tests/testthat/test-ard_stats_wilcox_test.R b/tests/testthat/test-ard_stats_wilcox_test.R index 82c7a7837..a8fc09e1d 100644 --- a/tests/testthat/test-ard_stats_wilcox_test.R +++ b/tests/testthat/test-ard_stats_wilcox_test.R @@ -1,4 +1,4 @@ -skip_if_not(cards::is_pkg_installed("broom", reference_pkg = "cardx")) +skip_if_not(is_pkg_installed("broom", reference_pkg = "cardx")) test_that("ard_stats_wilcox_test() works", { # One Sample Wilcox works diff --git a/tests/testthat/test-ard_survey_svychisq.R b/tests/testthat/test-ard_survey_svychisq.R index c94cfd865..894fbbd8b 100644 --- a/tests/testthat/test-ard_survey_svychisq.R +++ b/tests/testthat/test-ard_survey_svychisq.R @@ -1,4 +1,4 @@ -skip_if_not(cards::is_pkg_installed(c("survey", "broom"), reference_pkg = "cardx")) +skip_if_not(is_pkg_installed(c("survey", "broom"), reference_pkg = "cardx")) test_that("ard_survey_svychisq() works", { data(api, package = "survey") diff --git a/tests/testthat/test-ard_survey_svycontinuous.R b/tests/testthat/test-ard_survey_svycontinuous.R index dfcd27496..85e737ce7 100644 --- a/tests/testthat/test-ard_survey_svycontinuous.R +++ b/tests/testthat/test-ard_survey_svycontinuous.R @@ -1,4 +1,4 @@ -skip_if_not(cards::is_pkg_installed("survey", reference_pkg = "cardx")) +skip_if_not(is_pkg_installed("survey", reference_pkg = "cardx")) test_that("unstratified ard_survey_svycontinuous() works", { data(api, package = "survey") diff --git a/tests/testthat/test-ard_survey_svyranktest.R b/tests/testthat/test-ard_survey_svyranktest.R index eb74b9b6f..610beb4ae 100644 --- a/tests/testthat/test-ard_survey_svyranktest.R +++ b/tests/testthat/test-ard_survey_svyranktest.R @@ -1,4 +1,4 @@ -skip_if_not(cards::is_pkg_installed(c("survey", "broom"), reference_pkg = "cardx")) +skip_if_not(is_pkg_installed(c("survey", "broom"), reference_pkg = "cardx")) test_that("ard_survey_svyranktest() works", { data(api, package = "survey") diff --git a/tests/testthat/test-ard_survey_svyttest.R b/tests/testthat/test-ard_survey_svyttest.R index 529b7561b..c1d04eb34 100644 --- a/tests/testthat/test-ard_survey_svyttest.R +++ b/tests/testthat/test-ard_survey_svyttest.R @@ -1,4 +1,4 @@ -skip_if_not(cards::is_pkg_installed(c("survey", "broom"), reference_pkg = "cardx")) +skip_if_not(is_pkg_installed(c("survey", "broom"), reference_pkg = "cardx")) test_that("ard_survey_svyttest() works", { data(api, package = "survey") diff --git a/tests/testthat/test-ard_survival_survfit.R b/tests/testthat/test-ard_survival_survfit.R index 70301e62f..d12d4ac32 100644 --- a/tests/testthat/test-ard_survival_survfit.R +++ b/tests/testthat/test-ard_survival_survfit.R @@ -1,4 +1,4 @@ -skip_if_not(cards::is_pkg_installed(c("survival", "broom"), reference_pkg = "cardx")) +skip_if_not(is_pkg_installed(c("survival", "broom"), reference_pkg = "cardx")) test_that("ard_survival_survfit() works with times provided", { expect_snapshot( diff --git a/tests/testthat/test-proportion_ci.R b/tests/testthat/test-proportion_ci.R index 8e0b1a326..0129a5b94 100644 --- a/tests/testthat/test-proportion_ci.R +++ b/tests/testthat/test-proportion_ci.R @@ -1,4 +1,4 @@ -skip_if_not(cards::is_pkg_installed("broom", reference_pkg = "cardx")) +skip_if_not(do.call(asNamespace("cardx")$is_pkg_installed, list(pkg = "broom", reference_pkg = "cardx"))) test_that("check the proportion_ci_*() functions work", { # setting vectors to test