From 8a62e2c17806143c01e69606afeb52cb4e502c1c Mon Sep 17 00:00:00 2001 From: ddsjoberg Date: Wed, 21 Aug 2024 20:03:29 +0000 Subject: [PATCH 1/2] [skip actions] Bump version to 0.2.0.9007 --- DESCRIPTION | 2 +- NEWS.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 293df1786..f3b213a22 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: cardx Title: Extra Analysis Results Data Utilities -Version: 0.2.0.9006 +Version: 0.2.0.9007 Authors@R: c( person("Daniel", "Sjoberg", , "danield.sjoberg@gmail.com", role = c("aut", "cre")), person("Abinaya", "Yogasekaram", , "abinaya.yogasekaram@contractors.roche.com", role = "aut"), diff --git a/NEWS.md b/NEWS.md index 9b558d3b7..5313ad9c6 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,4 +1,4 @@ -# cardx 0.2.0.9006 +# cardx 0.2.0.9007 * Bug fix in `ard_categorical.survey.design()` where all unweighted statistics were returned, even in the case where they were explicitly not requested. From bb007644b8fd3145897be1e76f7413a42f487640 Mon Sep 17 00:00:00 2001 From: Emily de la Rua <59304861+edelarua@users.noreply.github.com> Date: Wed, 21 Aug 2024 16:45:53 -0400 Subject: [PATCH 2/2] Implement `cards::as_card()` (#201) **What changes are proposed in this pull request?** * Implement `cards::as_card()` where needed in the package to convert data frames to class 'card'. Closes #200 -------------------------------------------------------------------------------- Pre-review Checklist (if item does not apply, mark is as complete) - [x] **All** GitHub Action workflows pass with a :white_check_mark: - [x] PR branch has pulled the most recent updates from master branch: `usethis::pr_merge_main()` - [x] If a bug was fixed, a unit test was added. - [x] If a new `ard_*()` function was added, it passes the ARD structural checks from `cards::check_ard_structure()`. - [x] If a new `ard_*()` function was added, `set_cli_abort_call()` has been set. - [x] If a new `ard_*()` function was added and it depends on another package (such as, `broom`), `is_pkg_installed("broom", reference_pkg = "cardx")` has been set in the function call and the following added to the roxygen comments: `@examplesIf do.call(asNamespace("cardx")$is_pkg_installed, list(pkg = "broom"", reference_pkg = "cardx"))` - [x] Code coverage is suitable for any new functions/features (generally, 100% coverage for new code): `devtools::test_coverage()` Reviewer Checklist (if item does not apply, mark is as complete) - [ ] If a bug was fixed, a unit test was added. - [ ] Code coverage is suitable for any new functions/features: `devtools::test_coverage()` When the branch is ready to be merged: - [x] Update `NEWS.md` with the changes from this pull request under the heading "`# cardx (development version)`". If there is an issue associated with the pull request, reference it in parentheses at the end update (see `NEWS.md` for examples). - [x] **All** GitHub Action workflows pass with a :white_check_mark: - [ ] Approve Pull Request - [ ] Merge the PR. Please use "Squash and merge" or "Rebase and merge". --- NEWS.md | 2 ++ R/ard_aod_wald_test.R | 4 ++-- R/ard_car_anova.R | 4 ++-- R/ard_car_vif.R | 4 ++-- R/ard_categorical.survey.design.R | 15 ++++++--------- R/ard_categorical_ci.R | 6 ++++++ R/ard_categorical_ci.survey.design.R | 12 +++++++----- R/ard_continuous.survey.design.R | 8 ++++---- R/ard_continuous_ci.R | 7 +++++++ R/ard_continuous_ci.survey.design.R | 12 +++++++----- R/ard_dichotomous.survey.design.R | 4 ++-- R/ard_effectsize_cohens_d.R | 10 ++++++---- R/ard_effectsize_hedges_g.R | 11 ++++++----- R/ard_emmeans_mean_difference.R | 4 ++-- R/ard_missing.survey.design.R | 9 +++++++-- R/ard_smd_smd.R | 6 +++--- R/ard_stats_anova.R | 4 ++-- R/ard_stats_aov.R | 4 ++-- R/ard_stats_chisq_test.R | 8 +++++--- R/ard_stats_fisher_test.R | 8 +++++--- R/ard_stats_kruskal_test.R | 8 +++++--- R/ard_stats_mcnemar_test.R | 11 +++++++---- R/ard_stats_mood_test.R | 7 ++++--- R/ard_stats_oneway_test.R | 1 + R/ard_stats_prop_test.R | 5 +++-- R/ard_stats_t_test.R | 9 +++++---- R/ard_stats_t_test_onesample.R | 9 +++++---- R/ard_stats_wilcox_test.R | 9 +++++---- R/ard_stats_wilcox_test_onesample.R | 9 +++++---- R/ard_survey_svychisq.R | 8 +++++--- R/ard_survey_svyranktest.R | 6 ++++++ R/ard_survey_svyttest.R | 6 ++++++ R/ard_survival_survdiff.R | 4 ++-- R/ard_survival_survfit.R | 2 +- R/ard_survival_survfit_diff.R | 4 ++-- .../test-ard_categorical_ci.survey.design.R | 2 +- .../test-ard_continuous_ci.survey.design.R | 2 +- tests/testthat/test-ard_stats_t_test_onesample.R | 2 +- .../test-ard_stats_wilcox_test_onesample.R | 2 +- 39 files changed, 151 insertions(+), 97 deletions(-) diff --git a/NEWS.md b/NEWS.md index 5313ad9c6..e18d65df9 100644 --- a/NEWS.md +++ b/NEWS.md @@ -6,6 +6,8 @@ * Added `warning` and `error` columns to `ard_regression()` output. (#148) +* Implemented `cards::as_card()` where needed in the package to convert data frames to class 'card'. (#200) + # cardx 0.2.0 ### Breaking Changes diff --git a/R/ard_aod_wald_test.R b/R/ard_aod_wald_test.R index ecb883980..f7288c3f5 100644 --- a/R/ard_aod_wald_test.R +++ b/R/ard_aod_wald_test.R @@ -101,8 +101,8 @@ ard_aod_wald_test <- function(x, tidy_fun = broom.helpers::tidy_with_broom_or_pa warning = wald_test["warning"], error = wald_test["error"] ) |> - cards::tidy_ard_column_order() %>% - {structure(., class = c("card", class(.)))} # styler: off + cards::as_card() |> + cards::tidy_ard_column_order() } #' Extract data from wald.test object diff --git a/R/ard_car_anova.R b/R/ard_car_anova.R index 0e112d04f..e273382ec 100644 --- a/R/ard_car_anova.R +++ b/R/ard_car_anova.R @@ -69,6 +69,6 @@ ard_car_anova <- function(x, ...) { warning = car_anova["warning"], error = car_anova["error"] ) |> - cards::tidy_ard_column_order() %>% - {structure(., class = c("card", class(.)))} # styler: off + cards::as_card() |> + cards::tidy_ard_column_order() } diff --git a/R/ard_car_vif.R b/R/ard_car_vif.R index 74088eb4b..66ad23728 100644 --- a/R/ard_car_vif.R +++ b/R/ard_car_vif.R @@ -100,6 +100,6 @@ ard_car_vif <- function(x, ...) { # Clean up return object vif_return |> - cards::tidy_ard_column_order() %>% - {structure(., class = c("card", class(.)))} # styler: off + cards::as_card() |> + cards::tidy_ard_column_order() } diff --git a/R/ard_categorical.survey.design.R b/R/ard_categorical.survey.design.R index 7cd33deab..2bb29e431 100644 --- a/R/ard_categorical.survey.design.R +++ b/R/ard_categorical.survey.design.R @@ -72,8 +72,10 @@ ard_categorical.survey.design <- function(data, variables <- setdiff(variables, by) check_scalar(by, allow_empty = TRUE) - # if no variables selected, return empty data frame - if (is_empty(variables)) return(dplyr::tibble()) # styler: off + # return empty ARD if no variables selected ---------------------------------- + if (is_empty(variables)) { + return(dplyr::tibble() |> cards::as_card()) + } check_na_factor_levels(data$variables, c(by, variables)) @@ -97,11 +99,6 @@ ard_categorical.survey.design <- function(data, ) denominator <- arg_match(denominator) - # return empty tibble if no variables selected ------------------------------- - if (is_empty(variables)) { - return(dplyr::tibble()) - } - # check the missingness walk( variables, @@ -215,8 +212,8 @@ ard_categorical.survey.design <- function(data, warning = list(NULL), error = list(NULL), ) |> - cards::tidy_ard_column_order() %>% - {structure(., class = c("card", class(.)))} |> # styler: off + cards::as_card() |> + cards::tidy_ard_column_order() |> cards::tidy_ard_row_order() } diff --git a/R/ard_categorical_ci.R b/R/ard_categorical_ci.R index 21a96a6a6..8200dc128 100644 --- a/R/ard_categorical_ci.R +++ b/R/ard_categorical_ci.R @@ -76,6 +76,12 @@ ard_categorical_ci.data.frame <- function(data, data[variables], value = value ) + check_not_missing(variables) + + # return empty ARD if no variables selected ---------------------------------- + if (is_empty(variables)) { + return(dplyr::tibble() |> cards::as_card()) + } # calculate confidence intervals --------------------------------------------- map( diff --git a/R/ard_categorical_ci.survey.design.R b/R/ard_categorical_ci.survey.design.R index 539a2c54c..82347ae31 100644 --- a/R/ard_categorical_ci.survey.design.R +++ b/R/ard_categorical_ci.survey.design.R @@ -50,6 +50,11 @@ ard_categorical_ci.survey.design <- function(data, check_scalar_range(conf.level, range = c(0, 1)) method <- arg_match(method) + # return empty ARD if no variables selected ---------------------------------- + if (is_empty(variables)) { + return(dplyr::tibble() |> cards::as_card()) + } + # calculate and return ARD of one sample CI ---------------------------------- .calculate_ard_onesample_survey_ci( FUN = .svyciprop_wrapper, @@ -65,9 +70,6 @@ ard_categorical_ci.survey.design <- function(data, } .calculate_ard_onesample_survey_ci <- function(FUN, data, variables, by, conf.level, value, ...) { - # return empty data frame if no variables to process ------------------------- - if (is_empty(variables)) return(dplyr::tibble()) # styler: off - # calculate results ---------------------------------------------------------- map( variables, @@ -142,8 +144,8 @@ ard_categorical_ci.survey.design <- function(data, stat_label = .data$stat_name, fmt_fn = map(.data$stat, ~ case_switch(is.numeric(.x) ~ 2L, .default = as.character)) ) |> - cards::tidy_ard_column_order() %>% - structure(., class = c("card", class(.))) + cards::as_card() |> + cards::tidy_ard_column_order() # if a value was passed for the variable, subset on those results if (!is_empty(value)) { diff --git a/R/ard_continuous.survey.design.R b/R/ard_continuous.survey.design.R index 27c904763..0fe3617da 100644 --- a/R/ard_continuous.survey.design.R +++ b/R/ard_continuous.survey.design.R @@ -81,9 +81,9 @@ ard_continuous.survey.design <- function(data, variables, by = NULL, ) ) - # return empty tibble if no variables selected ------------------------------- + # return empty ARD if no variables selected ---------------------------------- if (is_empty(variables)) { - return(dplyr::tibble()) + return(dplyr::tibble() |> cards::as_card()) } # compute the weighted statistics -------------------------------------------- @@ -147,8 +147,8 @@ ard_continuous.survey.design <- function(data, variables, by = NULL, # add class and return ARD object -------------------------------------------- df_stats |> dplyr::mutate(context = "continuous") |> - cards::tidy_ard_column_order() %>% - {structure(., class = c("card", class(.)))} # styler: off + cards::as_card() |> + cards::tidy_ard_column_order() } .default_svy_stat_labels <- function(stat_label = NULL) { diff --git a/R/ard_continuous_ci.R b/R/ard_continuous_ci.R index 67d9b50a9..57ed23f52 100644 --- a/R/ard_continuous_ci.R +++ b/R/ard_continuous_ci.R @@ -30,6 +30,13 @@ ard_continuous_ci.data.frame <- function(data, variables, by = dplyr::group_vars # check inputs --------------------------------------------------------------- method <- arg_match(method) + check_not_missing(variables) + cards::process_selectors(data, by = {{ by }}, variables = {{ variables }}) + + # return empty ARD if no variables selected ---------------------------------- + if (is_empty(variables)) { + return(dplyr::tibble() |> cards::as_card()) + } # calculate CIs -------------------------------------------------------------- switch(method, diff --git a/R/ard_continuous_ci.survey.design.R b/R/ard_continuous_ci.survey.design.R index a8579dbec..60878f2ed 100644 --- a/R/ard_continuous_ci.survey.design.R +++ b/R/ard_continuous_ci.survey.design.R @@ -59,6 +59,11 @@ ard_continuous_ci.survey.design <- function(data, } ) + # return empty ARD if no variables selected ---------------------------------- + if (is_empty(variables)) { + return(dplyr::tibble() |> cards::as_card()) + } + # calculate and return ARD of one sample CI ---------------------------------- .calculate_ard_continuous_survey_ci( FUN = ifelse(method == "svymean", .svymean_confint_wrapper, .svyquantile_confint_wrapper), @@ -73,9 +78,6 @@ ard_continuous_ci.survey.design <- function(data, } .calculate_ard_continuous_survey_ci <- function(FUN, data, variables, by, conf.level, ...) { - # return empty data frame if no variables to process ------------------------- - if (is_empty(variables)) return(dplyr::tibble()) # styler: off - # calculate results ---------------------------------------------------------- map( variables, @@ -143,8 +145,8 @@ ard_continuous_ci.survey.design <- function(data, stat_label = .data$stat_name, fmt_fn = map(.data$stat, ~ case_switch(is.numeric(.x) ~ 2L, .default = as.character)) ) |> - cards::tidy_ard_column_order() %>% - structure(., class = c("card", class(.))) + cards::as_card() |> + cards::tidy_ard_column_order() } .svymean_confint_wrapper <- function(data, variable, conf.level, df, ...) { diff --git a/R/ard_dichotomous.survey.design.R b/R/ard_dichotomous.survey.design.R index d7b023586..99180f472 100644 --- a/R/ard_dichotomous.survey.design.R +++ b/R/ard_dichotomous.survey.design.R @@ -46,9 +46,9 @@ ard_dichotomous.survey.design <- function(data, ) .check_dichotomous_value(data$variables, value) - # return empty tibble if no variables selected ------------------------------- + # return empty ARD if no variables selected ---------------------------------- if (is_empty(variables)) { - return(dplyr::tibble()) + return(dplyr::tibble() |> cards::as_card()) } # calculate summary statistics ----------------------------------------------- diff --git a/R/ard_effectsize_cohens_d.R b/R/ard_effectsize_cohens_d.R index e57890d7d..d7a59c049 100644 --- a/R/ard_effectsize_cohens_d.R +++ b/R/ard_effectsize_cohens_d.R @@ -63,9 +63,10 @@ ard_effectsize_cohens_d <- function(data, by, variables, conf.level = 0.95, ...) cards::process_selectors(data, by = {{ by }}, variables = {{ variables }}) check_scalar(by) check_range(conf.level, range = c(0, 1)) - # if no variables selected, return empty tibble ------------------------------ + + # return empty ARD if no variables selected ---------------------------------- if (is_empty(variables)) { - return(dplyr::tibble()) + return(dplyr::tibble() |> cards::as_card()) } # build ARD ------------------------------------------------------------------ @@ -116,9 +117,9 @@ ard_effectsize_paired_cohens_d <- function(data, by, variables, id, conf.level = check_scalar(id) check_range(conf.level, range = c(0, 1)) - # if no variables selected, return empty tibble ------------------------------ + # return empty ARD if no variables selected ---------------------------------- if (is_empty(variables)) { - return(dplyr::tibble()) + return(dplyr::tibble() |> cards::as_card()) } # build ARD ------------------------------------------------------------------ @@ -206,5 +207,6 @@ ard_effectsize_paired_cohens_d <- function(data, by, variables, id, conf.level = by = "stat_name" ) |> dplyr::mutate(stat_label = dplyr::coalesce(.data$stat_label, .data$stat_name)) |> + cards::as_card() |> cards::tidy_ard_column_order() } diff --git a/R/ard_effectsize_hedges_g.R b/R/ard_effectsize_hedges_g.R index 2d1a68224..97c4eff87 100644 --- a/R/ard_effectsize_hedges_g.R +++ b/R/ard_effectsize_hedges_g.R @@ -63,9 +63,9 @@ ard_effectsize_hedges_g <- function(data, by, variables, conf.level = 0.95, ...) check_scalar(by) check_range(conf.level, range = c(0, 1)) - # if no variables selected, return empty tibble ------------------------------ + # return empty ARD if no variables selected ---------------------------------- if (is_empty(variables)) { - return(dplyr::tibble()) + return(dplyr::tibble() |> cards::as_card()) } # build ARD ------------------------------------------------------------------ @@ -115,12 +115,12 @@ ard_effectsize_paired_hedges_g <- function(data, by, variables, id, conf.level = check_scalar(id) check_range(conf.level, range = c(0, 1)) - # if no variables selected, return empty tibble ------------------------------ + # return empty ARD if no variables selected ---------------------------------- if (is_empty(variables)) { - return(dplyr::tibble()) + return(dplyr::tibble() |> cards::as_card()) } - # build ARD ------------------------------------------------------------------ + # build ARD ------------------------------------------------------------------ lapply( variables, function(variable) { @@ -190,5 +190,6 @@ ard_effectsize_paired_hedges_g <- function(data, by, variables, id, conf.level = by = "stat_name" ) |> dplyr::mutate(stat_label = dplyr::coalesce(.data$stat_label, .data$stat_name)) |> + cards::as_card() |> cards::tidy_ard_column_order() } diff --git a/R/ard_emmeans_mean_difference.R b/R/ard_emmeans_mean_difference.R index ac6fdff7a..0ea5ff56f 100644 --- a/R/ard_emmeans_mean_difference.R +++ b/R/ard_emmeans_mean_difference.R @@ -129,6 +129,6 @@ ard_emmeans_mean_difference <- function(data, formula, method, error = list(NULL), fmt_fn = map(.data$stat, \(.x) if (is.numeric(.x)) 1L else NULL) # styler: off ) |> - cards::tidy_ard_column_order() %>% - {structure(., class = c("card", class(.)))} # styler: off + cards::as_card() |> + cards::tidy_ard_column_order() } diff --git a/R/ard_missing.survey.design.R b/R/ard_missing.survey.design.R index 8cb4ad585..acb90c007 100644 --- a/R/ard_missing.survey.design.R +++ b/R/ard_missing.survey.design.R @@ -47,6 +47,11 @@ ard_missing.survey.design <- function(data, by = {{ by }} ) + # return empty ARD if no variables selected ---------------------------------- + if (is_empty(variables)) { + return(dplyr::tibble() |> cards::as_card()) + } + # convert all variables to T/F whether it's missing -------------------------- data$variables <- data$variables |> dplyr::mutate(across(all_of(variables), Negate(is.na))) @@ -126,6 +131,6 @@ ard_missing.survey.design <- function(data, # return final object -------------------------------------------------------- result |> dplyr::mutate(context = "missing") |> - cards::tidy_ard_column_order() %>% - {structure(., class = c("card", class(.)))} # styler: off + cards::as_card() |> + cards::tidy_ard_column_order() } diff --git a/R/ard_smd_smd.R b/R/ard_smd_smd.R index b7ed54650..872400bcf 100644 --- a/R/ard_smd_smd.R +++ b/R/ard_smd_smd.R @@ -44,7 +44,6 @@ ard_smd_smd <- function(data, by, variables, std.error = TRUE, conf.level = 0.95 data <- design$variables } - # continue check/process inputs ---------------------------------------------- check_data_frame(data) data <- dplyr::ungroup(data) @@ -53,9 +52,9 @@ ard_smd_smd <- function(data, by, variables, std.error = TRUE, conf.level = 0.95 # This check can be relaxed, but would require some changes to handle multi-row outputs check_n_levels(data[[by]], 2L, message = "The {.arg by} column must have {.val {length}} levels.") - # if no variables selected, return empty tibble ------------------------------ + # return empty ARD if no variables selected ---------------------------------- if (is_empty(variables)) { - return(dplyr::tibble()) + return(dplyr::tibble() |> cards::as_card()) } # build ARD ------------------------------------------------------------------ @@ -120,5 +119,6 @@ ard_smd_smd <- function(data, by, variables, std.error = TRUE, conf.level = 0.95 by = "stat_name" ) |> dplyr::mutate(stat_label = dplyr::coalesce(.data$stat_label, .data$stat_name)) |> + cards::as_card() |> cards::tidy_ard_column_order() } diff --git a/R/ard_stats_anova.R b/R/ard_stats_anova.R index fed73f8bd..17c6bfdc6 100644 --- a/R/ard_stats_anova.R +++ b/R/ard_stats_anova.R @@ -199,6 +199,6 @@ ard_stats_anova.data.frame <- function(x, .default = .data$stat_name ) ) |> - cards::tidy_ard_column_order() %>% - {structure(., class = c("card", class(.)))} # styler: off + cards::as_card() |> + cards::tidy_ard_column_order() } diff --git a/R/ard_stats_aov.R b/R/ard_stats_aov.R index 32bf29175..5af852644 100644 --- a/R/ard_stats_aov.R +++ b/R/ard_stats_aov.R @@ -53,6 +53,6 @@ ard_stats_aov <- function(formula, data, ...) { warning = aov["warning"], error = aov["error"] ) |> - cards::tidy_ard_column_order() %>% - {structure(., class = c("card", class(.)))} # styler: off + cards::as_card() |> + cards::tidy_ard_column_order() } diff --git a/R/ard_stats_chisq_test.R b/R/ard_stats_chisq_test.R index 8ab8c6ff8..48b47701f 100644 --- a/R/ard_stats_chisq_test.R +++ b/R/ard_stats_chisq_test.R @@ -34,10 +34,11 @@ ard_stats_chisq_test <- function(data, by, variables, ...) { cards::process_selectors(data, by = {{ by }}, variables = {{ variables }}) check_scalar(by) - # if no variables selected, return empty tibble ------------------------------ + # return empty ARD if no variables selected ---------------------------------- if (is_empty(variables)) { - return(dplyr::tibble()) + return(dplyr::tibble() |> cards::as_card()) } + # build ARD ------------------------------------------------------------------ lapply( variables, @@ -67,5 +68,6 @@ ard_stats_chisq_test <- function(data, by, variables, ...) { ) } ) |> - dplyr::bind_rows() + dplyr::bind_rows() |> + cards::as_card() } diff --git a/R/ard_stats_fisher_test.R b/R/ard_stats_fisher_test.R index 0831f45bc..e7b871792 100644 --- a/R/ard_stats_fisher_test.R +++ b/R/ard_stats_fisher_test.R @@ -37,10 +37,11 @@ ard_stats_fisher_test <- function(data, by, variables, conf.level = 0.95, ...) { check_scalar(by) check_range(conf.level, range = c(0, 1)) - # if no variables selected, return empty tibble ------------------------------ + # return empty ARD if no variables selected ---------------------------------- if (is_empty(variables)) { - return(dplyr::tibble()) + return(dplyr::tibble() |> cards::as_card()) } + # build ARD ------------------------------------------------------------------ lapply( variables, @@ -72,5 +73,6 @@ ard_stats_fisher_test <- function(data, by, variables, conf.level = 0.95, ...) { ) } ) |> - dplyr::bind_rows() + dplyr::bind_rows() |> + cards::as_card() } diff --git a/R/ard_stats_kruskal_test.R b/R/ard_stats_kruskal_test.R index 7f7b3b359..cff858178 100644 --- a/R/ard_stats_kruskal_test.R +++ b/R/ard_stats_kruskal_test.R @@ -33,10 +33,11 @@ ard_stats_kruskal_test <- function(data, by, variables) { cards::process_selectors(data, by = {{ by }}, variables = {{ variables }}) check_scalar(by) - # if no variables selected, return empty tibble ------------------------------ + # return empty ARD if no variables selected ---------------------------------- if (is_empty(variables)) { - return(dplyr::tibble()) + return(dplyr::tibble() |> cards::as_card()) } + # build ARD ------------------------------------------------------------------ lapply( variables, @@ -62,5 +63,6 @@ ard_stats_kruskal_test <- function(data, by, variables) { ) } ) |> - dplyr::bind_rows() + dplyr::bind_rows() |> + cards::as_card() } diff --git a/R/ard_stats_mcnemar_test.R b/R/ard_stats_mcnemar_test.R index bf3fa3063..7955af3de 100644 --- a/R/ard_stats_mcnemar_test.R +++ b/R/ard_stats_mcnemar_test.R @@ -58,10 +58,11 @@ ard_stats_mcnemar_test <- function(data, by, variables, ...) { cards::process_selectors(data, by = {{ by }}, variables = {{ variables }}) check_scalar(by) - # if no variables selected, return empty tibble ------------------------------ + # return empty ARD if no variables selected ---------------------------------- if (is_empty(variables)) { - return(dplyr::tibble()) + return(dplyr::tibble() |> cards::as_card()) } + # build ARD ------------------------------------------------------------------ lapply( variables, @@ -100,10 +101,11 @@ ard_stats_mcnemar_test_long <- function(data, by, variables, id, ...) { check_scalar(by) check_scalar(id) - # if no variables selected, return empty tibble ------------------------------ + # return empty ARD if no variables selected ---------------------------------- if (is_empty(variables)) { - return(dplyr::tibble()) + return(dplyr::tibble() |> cards::as_card()) } + # build ARD ------------------------------------------------------------------ lapply( variables, @@ -167,6 +169,7 @@ ard_stats_mcnemar_test_long <- function(data, by, variables, id, ...) { by = "stat_name" ) |> dplyr::mutate(stat_label = dplyr::coalesce(.data$stat_label, .data$stat_name)) |> + cards::as_card() |> cards::tidy_ard_column_order() } diff --git a/R/ard_stats_mood_test.R b/R/ard_stats_mood_test.R index 75d3464e4..c5ca5accb 100644 --- a/R/ard_stats_mood_test.R +++ b/R/ard_stats_mood_test.R @@ -40,11 +40,11 @@ ard_stats_mood_test <- function(data, by, variables, ...) { cards::process_selectors(data, by = {{ by }}, variables = {{ variables }}) check_scalar(by) - - # if no variables selected, return empty tibble ------------------------------ + # return empty ARD if no variables selected ---------------------------------- if (is_empty(variables)) { - return(dplyr::tibble()) + return(dplyr::tibble() |> cards::as_card()) } + # build ARD ------------------------------------------------------------------ lapply( variables, @@ -101,6 +101,7 @@ ard_stats_mood_test <- function(data, by, variables, ...) { by = "stat_name" ) |> dplyr::mutate(stat_label = dplyr::coalesce(.data$stat_label, .data$stat_name)) |> + cards::as_card() |> cards::tidy_ard_column_order() } diff --git a/R/ard_stats_oneway_test.R b/R/ard_stats_oneway_test.R index 60481d9e2..7129a1f59 100644 --- a/R/ard_stats_oneway_test.R +++ b/R/ard_stats_oneway_test.R @@ -58,5 +58,6 @@ ard_stats_oneway_test <- function(formula, data, ...) { dplyr::tibble(!!!map(as.list(attr(stats::terms(formula), "variables"))[-1], as_label)) %>% set_names(., c("variable", paste0("group", seq_len(length(.) - 1L)))) ) |> + cards::as_card() |> cards::tidy_ard_column_order() } diff --git a/R/ard_stats_prop_test.R b/R/ard_stats_prop_test.R index 1b4389814..94edda3d6 100644 --- a/R/ard_stats_prop_test.R +++ b/R/ard_stats_prop_test.R @@ -38,9 +38,9 @@ ard_stats_prop_test <- function(data, by, variables, conf.level = 0.95, ...) { check_scalar(by) data <- data[c(by, variables)] |> dplyr::ungroup() |> tidyr::drop_na() # styler: off - # if no variables selected, return empty tibble ------------------------------ + # return empty ARD if no variables selected ---------------------------------- if (is_empty(variables)) { - return(dplyr::tibble()) + return(dplyr::tibble() |> cards::as_card()) } # build ARD ------------------------------------------------------------------ @@ -122,6 +122,7 @@ ard_stats_prop_test <- function(data, by, variables, conf.level = 0.95, ...) { by = "stat_name" ) |> dplyr::mutate(stat_label = dplyr::coalesce(.data$stat_label, .data$stat_name)) |> + cards::as_card() |> cards::tidy_ard_column_order() } diff --git a/R/ard_stats_t_test.R b/R/ard_stats_t_test.R index f38411698..9205c9783 100644 --- a/R/ard_stats_t_test.R +++ b/R/ard_stats_t_test.R @@ -60,9 +60,9 @@ ard_stats_t_test <- function(data, variables, by = NULL, conf.level = 0.95, ...) check_scalar(by, allow_empty = TRUE) check_range(conf.level, range = c(0, 1)) - # if no variables selected, return empty tibble ------------------------------ + # return empty ARD if no variables selected ---------------------------------- if (is_empty(variables)) { - return(dplyr::tibble()) + return(dplyr::tibble() |> cards::as_card()) } # build ARD ------------------------------------------------------------------ @@ -106,9 +106,9 @@ ard_stats_paired_t_test <- function(data, by, variables, id, conf.level = 0.95, check_scalar(by) check_scalar(id) - # if no variables selected, return empty tibble ------------------------------ + # return empty ARD if no variables selected ---------------------------------- if (is_empty(variables)) { - return(dplyr::tibble()) + return(dplyr::tibble() |> cards::as_card()) } # build ARD ------------------------------------------------------------------ @@ -186,6 +186,7 @@ ard_stats_paired_t_test <- function(data, by, variables, id, conf.level = 0.95, by = "stat_name" ) |> dplyr::mutate(stat_label = dplyr::coalesce(.data$stat_label, .data$stat_name)) |> + cards::as_card() |> cards::tidy_ard_column_order() } diff --git a/R/ard_stats_t_test_onesample.R b/R/ard_stats_t_test_onesample.R index 1a419b21a..52861b67c 100644 --- a/R/ard_stats_t_test_onesample.R +++ b/R/ard_stats_t_test_onesample.R @@ -33,9 +33,9 @@ ard_stats_t_test_onesample <- function(data, variables, by = dplyr::group_vars(d cards::process_selectors(data, by = {{ by }}, variables = {{ variables }}) check_scalar_range(conf.level, range = c(0, 1)) - # if no variables selected, return empty tibble ------------------------------ + # return empty ARD if no variables selected ---------------------------------- if (is_empty(variables)) { - return(dplyr::tibble()) + return(dplyr::tibble() |> cards::as_card()) } cards::ard_continuous( @@ -66,6 +66,7 @@ ard_stats_t_test_onesample <- function(data, variables, by = dplyr::group_vars(d stat_label = dplyr::coalesce(.data$stat_label, .data$stat_name), context = "stats_t_test_onesample", ) |> - cards::tidy_ard_row_order() |> - cards::tidy_ard_column_order() + cards::as_card() |> + cards::tidy_ard_column_order() |> + cards::tidy_ard_row_order() } diff --git a/R/ard_stats_wilcox_test.R b/R/ard_stats_wilcox_test.R index 5972230bb..ef450b03f 100644 --- a/R/ard_stats_wilcox_test.R +++ b/R/ard_stats_wilcox_test.R @@ -60,9 +60,9 @@ ard_stats_wilcox_test <- function(data, variables, by = NULL, conf.level = 0.95, check_scalar(by, allow_empty = TRUE) check_range(conf.level, range = c(0, 1)) - # if no variables selected, return empty tibble ------------------------------ + # return empty ARD if no variables selected ---------------------------------- if (is_empty(variables)) { - return(dplyr::tibble()) + return(dplyr::tibble() |> cards::as_card()) } # build ARD ------------------------------------------------------------------ @@ -112,9 +112,9 @@ ard_stats_paired_wilcox_test <- function(data, by, variables, id, conf.level = 0 check_scalar(by) check_scalar(id) - # if no variables selected, return empty tibble ------------------------------ + # return empty ARD if no variables selected ---------------------------------- if (is_empty(variables)) { - return(dplyr::tibble()) + return(dplyr::tibble() |> cards::as_card()) } # build ARD ------------------------------------------------------------------ @@ -196,6 +196,7 @@ ard_stats_paired_wilcox_test <- function(data, by, variables, id, conf.level = 0 by = "stat_name" ) |> dplyr::mutate(stat_label = dplyr::coalesce(.data$stat_label, .data$stat_name)) |> + cards::as_card() |> cards::tidy_ard_column_order() } diff --git a/R/ard_stats_wilcox_test_onesample.R b/R/ard_stats_wilcox_test_onesample.R index 6a2310c99..4eb438876 100644 --- a/R/ard_stats_wilcox_test_onesample.R +++ b/R/ard_stats_wilcox_test_onesample.R @@ -33,9 +33,9 @@ ard_stats_wilcox_test_onesample <- function(data, variables, by = dplyr::group_v cards::process_selectors(data, by = {{ by }}, variables = {{ variables }}) check_scalar_range(conf.level, range = c(0, 1)) - # if no variables selected, return empty tibble ------------------------------ + # return empty ARD if no variables selected ---------------------------------- if (is_empty(variables)) { - return(dplyr::tibble()) + return(dplyr::tibble() |> cards::as_card()) } cards::ard_continuous( @@ -67,6 +67,7 @@ ard_stats_wilcox_test_onesample <- function(data, variables, by = dplyr::group_v stat_label = dplyr::coalesce(.data$stat_label, .data$stat_name), context = "stats_wilcox_test_onesample", ) |> - cards::tidy_ard_row_order() |> - cards::tidy_ard_column_order() + cards::as_card() |> + cards::tidy_ard_column_order() |> + cards::tidy_ard_row_order() } diff --git a/R/ard_survey_svychisq.R b/R/ard_survey_svychisq.R index 5ad520a42..abcd6c207 100644 --- a/R/ard_survey_svychisq.R +++ b/R/ard_survey_svychisq.R @@ -39,10 +39,11 @@ ard_survey_svychisq <- function(data, by, variables, statistic = "F", ...) { cards::process_selectors(data[["variables"]], by = {{ by }}, variables = {{ variables }}) check_scalar(by) - # if no variables selected, return empty tibble ------------------------------ + # return empty ARD if no variables selected ---------------------------------- if (is_empty(variables)) { - return(dplyr::tibble()) + return(dplyr::tibble() |> cards::as_card()) } + # build ARD ------------------------------------------------------------------ lapply( variables, @@ -70,5 +71,6 @@ ard_survey_svychisq <- function(data, by, variables, statistic = "F", ...) { ) } ) |> - dplyr::bind_rows() + dplyr::bind_rows() |> + cards::as_card() } diff --git a/R/ard_survey_svyranktest.R b/R/ard_survey_svyranktest.R index 33b015a60..dd3e5d912 100644 --- a/R/ard_survey_svyranktest.R +++ b/R/ard_survey_svyranktest.R @@ -39,6 +39,11 @@ ard_survey_svyranktest <- function(data, by, variables, test, ...) { cards::process_selectors(data[["variables"]], by = {{ by }}, variables = {{ variables }}) check_scalar(by) + # return empty ARD if no variables selected ---------------------------------- + if (is_empty(variables)) { + return(dplyr::tibble() |> cards::as_card()) + } + # build ARD ------------------------------------------------------------------ lapply( variables, @@ -78,6 +83,7 @@ ard_survey_svyranktest <- function(data, by, variables, test, ...) { by = "stat_name" ) |> dplyr::mutate(stat_label = dplyr::coalesce(.data$stat_label, .data$stat_name)) |> + cards::as_card() |> cards::tidy_ard_column_order() } diff --git a/R/ard_survey_svyttest.R b/R/ard_survey_svyttest.R index ac4ee7825..916cf7897 100644 --- a/R/ard_survey_svyttest.R +++ b/R/ard_survey_svyttest.R @@ -37,6 +37,11 @@ ard_survey_svyttest <- function(data, by, variables, conf.level = 0.95, ...) { cards::process_selectors(data[["variables"]], by = {{ by }}, variables = {{ variables }}) check_scalar(by) + # return empty ARD if no variables selected ---------------------------------- + if (is_empty(variables)) { + return(dplyr::tibble() |> cards::as_card()) + } + # build ARD ------------------------------------------------------------------ lapply( variables, @@ -85,5 +90,6 @@ ard_survey_svyttest <- function(data, by, variables, conf.level = 0.95, ...) { by = "stat_name" ) |> dplyr::mutate(stat_label = dplyr::coalesce(.data$stat_label, .data$stat_name)) |> + cards::as_card() |> cards::tidy_ard_column_order() } diff --git a/R/ard_survival_survdiff.R b/R/ard_survival_survdiff.R index 59a4cc3e5..9548b692f 100644 --- a/R/ard_survival_survdiff.R +++ b/R/ard_survival_survdiff.R @@ -95,8 +95,8 @@ ard_survival_survdiff <- function(formula, data, rho = 0, ...) { } ) ) |> - cards::tidy_ard_column_order() %>% - {structure(., class = c("card", class(.)))} # styler: off + cards::as_card() |> + cards::tidy_ard_column_order() } .variables_to_survdiff_ard <- function(variables, diff --git a/R/ard_survival_survfit.R b/R/ard_survival_survfit.R index e430eedc0..71c86e3bc 100644 --- a/R/ard_survival_survfit.R +++ b/R/ard_survival_survfit.R @@ -324,7 +324,7 @@ extract_multi_strata <- function(x, df_stat) { warning = list(NULL), error = list(NULL) ) %>% - structure(., class = c("card", class(.))) %>% + cards::as_card() %>% cards::tidy_ard_column_order() %>% cards::tidy_ard_row_order() } diff --git a/R/ard_survival_survfit_diff.R b/R/ard_survival_survfit_diff.R index 5700c2e5c..e5cd3fb67 100644 --- a/R/ard_survival_survfit_diff.R +++ b/R/ard_survival_survfit_diff.R @@ -116,6 +116,6 @@ ard_survival_survfit_diff <- function(x, times, conf.level = 0.95) { ), context = "survival_survfit_diff", ) |> - cards::tidy_ard_column_order() %>% - structure(., class = c("card", class(.))) + cards::as_card() |> + cards::tidy_ard_column_order() } diff --git a/tests/testthat/test-ard_categorical_ci.survey.design.R b/tests/testthat/test-ard_categorical_ci.survey.design.R index dad37b3e3..a1a0d8da0 100644 --- a/tests/testthat/test-ard_categorical_ci.survey.design.R +++ b/tests/testthat/test-ard_categorical_ci.survey.design.R @@ -25,7 +25,7 @@ test_that("ard_categorical_ci(variables)", { expect_equal( ard_categorical_ci(dclus1, variables = starts_with("xxxxxx")), - dplyr::tibble() + dplyr::tibble() |> cards::as_card() ) # check all works with numeric variable diff --git a/tests/testthat/test-ard_continuous_ci.survey.design.R b/tests/testthat/test-ard_continuous_ci.survey.design.R index aff4035ff..4d1b76fc3 100644 --- a/tests/testthat/test-ard_continuous_ci.survey.design.R +++ b/tests/testthat/test-ard_continuous_ci.survey.design.R @@ -35,7 +35,7 @@ test_that("ard_continuous_ci(variables)", { expect_equal( ard_continuous_ci(dclus1, variables = starts_with("xxxxxx")), - dplyr::tibble() + dplyr::tibble() |> cards::as_card() ) # check NA values don't affect result diff --git a/tests/testthat/test-ard_stats_t_test_onesample.R b/tests/testthat/test-ard_stats_t_test_onesample.R index df62e11c2..60badde25 100644 --- a/tests/testthat/test-ard_stats_t_test_onesample.R +++ b/tests/testthat/test-ard_stats_t_test_onesample.R @@ -45,6 +45,6 @@ test_that("ard_stats_t_test_onesample() works", { cards::ADSL, variables = character(0) ), - dplyr::tibble() + dplyr::tibble() |> cards::as_card() ) }) diff --git a/tests/testthat/test-ard_stats_wilcox_test_onesample.R b/tests/testthat/test-ard_stats_wilcox_test_onesample.R index 3bd22c238..4366938ba 100644 --- a/tests/testthat/test-ard_stats_wilcox_test_onesample.R +++ b/tests/testthat/test-ard_stats_wilcox_test_onesample.R @@ -47,6 +47,6 @@ test_that("ard_stats_wilcox_test_onesample() works", { cards::ADSL, variables = character(0) ), - dplyr::tibble() + dplyr::tibble() |> cards::as_card() ) })