Skip to content

Commit

Permalink
general renaming (#58)
Browse files Browse the repository at this point in the history
**What changes are proposed in this pull request?**
* Style this entry in a way that can be copied directly into `NEWS.md`.
(#<issue number>, @<username>)

Provide more detail here as needed.

**Reference GitHub issue associated with pull request.** _e.g., 'closes
#<issue number>'_



--------------------------------------------------------------------------------

Pre-review Checklist (if item does not apply, mark is as complete)
- [ ] **All** GitHub Action workflows pass with a ✅
- [ ] PR branch has pulled the most recent updates from master branch:
`usethis::pr_merge_main()`
- [ ] If a bug was fixed, a unit test was added.
- [ ] Code coverage is suitable for any new functions/features
(generally, 100% coverage for new code): `devtools::test_coverage()`
- [ ] Request a reviewer

Reviewer Checklist (if item does not apply, mark is as complete)

- [ ] If a bug was fixed, a unit test was added.
- [ ] Run `pkgdown::build_site()`. Check the R console for errors, and
review the rendered website.
- [ ] Code coverage is suitable for any new functions/features:
`devtools::test_coverage()`

When the branch is ready to be merged:
- [ ] Update `NEWS.md` with the changes from this pull request under the
heading "`# cards (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).
- [ ] **All** GitHub Action workflows pass with a ✅
- [ ] Approve Pull Request
- [ ] Merge the PR. Please use "Squash and merge" or "Rebase and merge".
  • Loading branch information
ddsjoberg committed Feb 21, 2024
1 parent cff2b9d commit ddbd012
Show file tree
Hide file tree
Showing 10 changed files with 81 additions and 96 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ BugReports: https://github.com/insightsengineering/cardx/issues
Depends:
R (>= 4.1)
Imports:
cards (>= 0.0.0.9048),
cards (>= 0.0.0.9049),
cli (>= 3.6.1),
dplyr (>= 1.1.2),
glue (>= 1.6.2),
Expand Down
2 changes: 1 addition & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ export(any_of)
export(ard_chisqtest)
export(ard_fishertest)
export(ard_kruskaltest)
export(ard_moodtest)
export(ard_mcnemartest)
export(ard_moodtest)
export(ard_paired_ttest)
export(ard_paired_wilcoxtest)
export(ard_proportion_ci)
Expand Down
8 changes: 4 additions & 4 deletions R/ard_regression.R
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@ ard_regression.default <- function(x, tidy_fun = broom.helpers::tidy_with_broom_
tidyr::pivot_longer(
cols = -c("variable", "variable_level"),
names_to = "stat_name",
values_to = "statistic"
values_to = "stat"
) |>
dplyr::filter(map_lgl(.data$statistic, Negate(is.na))) |>
dplyr::filter(map_lgl(.data$stat, Negate(is.na))) |>
dplyr::mutate(
statistic_fmt_fn =
fmt_fn =
lapply(
.data$statistic,
.data$stat,
function(x) {
switch(is.integer(x), 0L) %||% # styler: off
switch(is.numeric(x), 1L) # styler: off
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/_snaps/ard_chisqtest.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
by = "ARM", variable = "AGEGR1"), ard_chisqtest(data = adsl_sub, by = "SEX",
variable = "AGEGR1"))))
Output
ARM SEX variable context stat_name statistic
ARM SEX variable context stat_name stat
1 Overall ARM <NA> AGEGR1 chisqtest statistic 5.079442e+00
2 Overall ARM <NA> AGEGR1 chisqtest p.value 7.888842e-02
3 Overall ARM <NA> AGEGR1 chisqtest parameter 2.000000e+00
Expand Down
10 changes: 5 additions & 5 deletions tests/testthat/_snaps/ard_kruskaltest.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
2 ARM AGE kruskaltest p.value p-value
3 ARM AGE kruskaltest parameter Degrees of Freedom
4 ARM AGE kruskaltest method method
statistic statistic_fmt_fn warning error
1 1.63473 1 NULL NULL
2 0.4415937 1 NULL NULL
3 2 1 NULL NULL
4 Kruskal-Wallis rank sum test NULL NULL NULL
stat fmt_fn warning error
1 1.63473 1 NULL NULL
2 0.4415937 1 NULL NULL
3 2 1 NULL NULL
4 Kruskal-Wallis rank sum test NULL NULL NULL

10 changes: 5 additions & 5 deletions tests/testthat/_snaps/ard_moodtest.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
2 SEX AGE moodtest p.value p-value
3 SEX AGE moodtest method method
4 SEX AGE moodtest alternative Alternative Hypothesis
statistic statistic_fmt_fn warning error
1 0.1292194 1 NULL NULL
2 0.8971841 1 NULL NULL
3 Mood two-sample test of scale NULL NULL NULL
4 two.sided NULL NULL NULL
stat fmt_fn warning error
1 0.1292194 1 NULL NULL
2 0.8971841 1 NULL NULL
3 Mood two-sample test of scale NULL NULL NULL
4 two.sided NULL NULL NULL

28 changes: 14 additions & 14 deletions tests/testthat/_snaps/ard_proportion_ci.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
Message
{cards} data frame: 6 x 8
Output
variable context stat_name stat_label statistic statistic_fmt_fn
1 rsp proporti… N N 80 0
2 rsp proporti… estimate estimate 0.625 1
3 rsp proporti… conf.low conf.low 0.487 1
4 rsp proporti… conf.high conf.high 0.719 1
5 rsp proporti… conf.level conf.lev… 0.95 1
6 rsp proporti… method method Stratifi… <fn>
variable context stat_name stat_label stat fmt_fn
1 rsp proporti… N N 80 0
2 rsp proporti… estimate estimate 0.625 1
3 rsp proporti… conf.low conf.low 0.487 1
4 rsp proporti… conf.high conf.high 0.719 1
5 rsp proporti… conf.level conf.lev… 0.95 1
6 rsp proporti… method method Stratifi… <fn>
Message
i 2 more variables: warning, error

Expand All @@ -22,13 +22,13 @@
Message
{cards} data frame: 6 x 8
Output
variable context stat_name stat_label statistic statistic_fmt_fn
1 rsp proporti… N N 80 0
2 rsp proporti… estimate estimate 0.625 1
3 rsp proporti… conf.low conf.low 0.448 1
4 rsp proporti… conf.high conf.high 0.753 1
5 rsp proporti… conf.level conf.lev… 0.95 1
6 rsp proporti… method method Stratifi… <fn>
variable context stat_name stat_label stat fmt_fn
1 rsp proporti… N N 80 0
2 rsp proporti… estimate estimate 0.625 1
3 rsp proporti… conf.low conf.low 0.448 1
4 rsp proporti… conf.high conf.high 0.753 1
5 rsp proporti… conf.level conf.lev… 0.95 1
6 rsp proporti… method method Stratifi… <fn>
Message
i 2 more variables: warning, error

8 changes: 4 additions & 4 deletions tests/testthat/_snaps/ard_regression.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

Code
print(dplyr::mutate(ard_regression(lm(AGE ~ ARM, data = cards::ADSL),
add_estimate_to_reference_rows = TRUE), statistic = lapply(statistic, function(
x) ifelse(is.numeric(x), cards::round5(x, 3), x))), n = Inf)
add_estimate_to_reference_rows = TRUE), stat = lapply(stat, function(x) ifelse(
is.numeric(x), cards::round5(x, 3), x))), n = Inf)
Message
{cards} data frame: 43 x 7
Output
variable variable_level context stat_name stat_label statistic
variable variable_level context stat_name stat_label stat
1 ARM Placebo regressi… term term ARMPlace…
2 ARM Placebo regressi… var_label Label Descript…
3 ARM Placebo regressi… var_class Class character
Expand Down Expand Up @@ -52,5 +52,5 @@
42 ARM Xanomeli… regressi… conf.low CI Lower… -2.039
43 ARM Xanomeli… regressi… conf.high CI Upper… 2.953
Message
i 1 more variable: statistic_fmt_fn
i 1 more variable: fmt_fn

105 changes: 45 additions & 60 deletions tests/testthat/_snaps/ard_ttest.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,73 +3,58 @@
Code
as.data.frame(ard_ttest(cards::ADSL, by = ARM, variable = AGE, var.equal = TRUE))
Output
group1 variable context stat_name stat_label statistic
1 ARM AGE ttest estimate Mean Difference NULL
2 ARM AGE ttest estimate1 Group 1 Mean NULL
3 ARM AGE ttest estimate2 Group 2 Mean NULL
4 ARM AGE ttest statistic t Statistic NULL
5 ARM AGE ttest p.value p-value NULL
6 ARM AGE ttest parameter Degrees of Freedom NULL
7 ARM AGE ttest conf.low CI Lower Bound NULL
8 ARM AGE ttest conf.high CI Upper Bound NULL
9 ARM AGE ttest method method NULL
10 ARM AGE ttest alternative alternative NULL
11 ARM AGE ttest mu H0 Mean 0
12 ARM AGE ttest paired Paired t-test FALSE
13 ARM AGE ttest var.equal Equal Variances TRUE
14 ARM AGE ttest conf.level CI Confidence Level 0.95
statistic_fmt_fn warning error
1 NULL NULL grouping factor must have exactly 2 levels
2 NULL NULL grouping factor must have exactly 2 levels
3 NULL NULL grouping factor must have exactly 2 levels
4 NULL NULL grouping factor must have exactly 2 levels
5 NULL NULL grouping factor must have exactly 2 levels
6 NULL NULL grouping factor must have exactly 2 levels
7 NULL NULL grouping factor must have exactly 2 levels
8 NULL NULL grouping factor must have exactly 2 levels
9 NULL NULL grouping factor must have exactly 2 levels
10 NULL NULL grouping factor must have exactly 2 levels
11 1 NULL grouping factor must have exactly 2 levels
12 NULL NULL grouping factor must have exactly 2 levels
13 NULL NULL grouping factor must have exactly 2 levels
14 1 NULL grouping factor must have exactly 2 levels
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 statistic
1 ARM AGE ttest estimate Mean Difference NULL
2 ARM AGE ttest estimate1 Group 1 Mean NULL
3 ARM AGE ttest estimate2 Group 2 Mean NULL
4 ARM AGE ttest statistic t Statistic NULL
5 ARM AGE ttest p.value p-value NULL
6 ARM AGE ttest parameter Degrees of Freedom NULL
7 ARM AGE ttest conf.low CI Lower Bound NULL
8 ARM AGE ttest conf.high CI Upper Bound NULL
9 ARM AGE ttest method method NULL
10 ARM AGE ttest alternative alternative NULL
11 ARM AGE ttest mu H0 Mean 0
12 ARM AGE ttest paired Paired t-test TRUE
13 ARM AGE ttest var.equal Equal Variances TRUE
14 ARM AGE ttest conf.level CI Confidence Level 0.95
statistic_fmt_fn warning
1 NULL NULL
2 NULL NULL
3 NULL NULL
4 NULL NULL
5 NULL NULL
6 NULL NULL
7 NULL NULL
8 NULL NULL
9 NULL NULL
10 NULL NULL
11 1 NULL
12 NULL NULL
13 NULL NULL
14 1 NULL
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.
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-ard_regression.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ test_that("ard_regression() works", {
lm(AGE ~ ARM, data = cards::ADSL) |>
ard_regression(add_estimate_to_reference_rows = TRUE) |>
dplyr::mutate(
statistic = lapply(statistic, function(x) ifelse(is.numeric(x), cards::round5(x, 3), x))
stat = lapply(stat, function(x) ifelse(is.numeric(x), cards::round5(x, 3), x))
) |>
print(n = Inf)
)
Expand Down

0 comments on commit ddbd012

Please sign in to comment.