From f9dc75379974253b40e077e179dfc9bdad7f040e Mon Sep 17 00:00:00 2001 From: Daniel Sjoberg Date: Wed, 26 Jun 2024 10:26:05 -0700 Subject: [PATCH] progress --- R/ard_continuous.survey.design.R | 2 +- .../_snaps/ard_continuous.survey.design.md | 23 ++++++++++--------- .../test-ard_continuous.survey.design.R | 6 +++-- 3 files changed, 17 insertions(+), 14 deletions(-) diff --git a/R/ard_continuous.survey.design.R b/R/ard_continuous.survey.design.R index 3d3a67c39..35bb13080 100644 --- a/R/ard_continuous.survey.design.R +++ b/R/ard_continuous.survey.design.R @@ -139,7 +139,7 @@ ard_continuous.survey.design <- function(data, variables, by = NULL, fmt_fn = map(.data$variable, ~ fmt_fn[[.x]] |> unname()) ) |> tidyr::unnest(cols = c("stat_name", "fmt_fn")), - by = "stat_name", + by = c("variable", "stat_name"), unmatched = "ignore" ) } diff --git a/tests/testthat/_snaps/ard_continuous.survey.design.md b/tests/testthat/_snaps/ard_continuous.survey.design.md index 526af04b7..545a0ccf0 100644 --- a/tests/testthat/_snaps/ard_continuous.survey.design.md +++ b/tests/testthat/_snaps/ard_continuous.survey.design.md @@ -22,18 +22,19 @@ # ard_continuous.survey.design(fmt_fn) Code - ard_continuous(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 + as.data.frame(dplyr::select(ard_continuous(dclus1, variables = c(api99, api00), + statistic = ~ c("mean", "median", "min", "max"), fmt_fn = list(api00 = list( + mean = 2, median = "xx.xx", min = as.character))), -warning, -error)) 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 + variable context stat_name stat_label stat fmt_fn + 1 api99 continuous mean Mean 606.9781 1 + 2 api99 continuous median Median 615 1 + 3 api99 continuous min Minimum 365 1 + 4 api99 continuous max Maximum 890 1 + 5 api00 continuous mean Mean 644.1694 2 + 6 api00 continuous median Median 652 xx.xx + 7 api00 continuous min Minimum 411 .Primitive("as.character") + 8 api00 continuous max Maximum 905 1 # ard_continuous.survey.design(stat_label) diff --git a/tests/testthat/test-ard_continuous.survey.design.R b/tests/testthat/test-ard_continuous.survey.design.R index 95232a5c1..e5a6e1a14 100644 --- a/tests/testthat/test-ard_continuous.survey.design.R +++ b/tests/testthat/test-ard_continuous.survey.design.R @@ -322,10 +322,12 @@ test_that("ard_continuous.survey.design(fmt_fn)", { expect_snapshot( ard_continuous( dclus1, - variables = api00, + variables = c(api99, api00), statistic = ~ c("mean", "median", "min", "max"), fmt_fn = list(api00 = list(mean = 2, median = "xx.xx", min = as.character)) - ) + ) |> + dplyr::select(-warning, -error) |> + as.data.frame() ) })