Skip to content

Commit 5212bf9

Browse files
authored
Fmt fn to fmt fun (#302)
**What changes are proposed in this pull request?** * Updating any `fmt_fn` references to `fmt_fun` for consistency. * Any function with an argument `cardx::foo(fmt_fn)` has been updated to `cardx::foo(fmt_fun)`. The old syntax will continue to function, but with a deprecation warning to users. * Importantly, the ARD column named `"fmt_fn"` has been updated to `"fmt_fun"`. This change cannot be formally deprecated. For users who were accessing the ARD object directly to modify this column instead of using functions like `cards::update_ard_fmt_fun()`, this will be a breaking change. -------------------------------------------------------------------------------- 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. - [ ] If a new `ard_*()` function was added, it passes the ARD structural checks from `cards::check_ard_structure()`. - [ ] If a new `ard_*()` function was added, `set_cli_abort_call()` has been set. - [ ] If a new `ard_*()` function was added and it depends on another package (such as, `broom`), `is_pkg_installed("broom")` 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""))` - [ ] 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: - [ ] 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). - [ ] **All** GitHub Action workflows pass with a ✅ - [ ] Approve Pull Request - [ ] Merge the PR. Please use "Squash and merge" or "Rebase and merge".
1 parent 1a8081a commit 5212bf9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+440
-369
lines changed

DESCRIPTION

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ BugReports: https://github.com/insightsengineering/cardx/issues
2020
Depends:
2121
R (>= 4.2)
2222
Imports:
23-
cards (>= 0.5.1),
23+
cards (>= 0.6.0.9011),
2424
cli (>= 3.6.1),
2525
dplyr (>= 1.1.2),
2626
glue (>= 1.6.2),
@@ -44,6 +44,7 @@ Suggests:
4444
survival (>= 3.6-4),
4545
testthat (>= 3.2.0),
4646
withr (>= 2.5.0)
47+
Remotes: insightsengineering/cards
4748
Config/Needs/website: insightsengineering/nesttemplate
4849
Config/testthat/edition: 3
4950
Config/testthat/parallel: true

NAMESPACE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,3 +108,4 @@ importFrom(dplyr,num_range)
108108
importFrom(dplyr,one_of)
109109
importFrom(dplyr,starts_with)
110110
importFrom(dplyr,where)
111+
importFrom(lifecycle,deprecated)

NEWS.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# cardx 0.2.4.9006
22

3+
* Updating any `fmt_fn` references to `fmt_fun` for consistency.
4+
5+
* Any function with an argument `cardx::foo(fmt_fn)` has been updated to `cardx::foo(fmt_fun)`. The old syntax will continue to function, but with a deprecation warning to users.
6+
7+
* Importantly, the ARD column named `"fmt_fn"` has been updated to `"fmt_fun"`. This change cannot be formally deprecated. For users who were accessing the ARD object directly to modify this column instead of using functions like `cards::update_ard_fmt_fun()`, this will be a breaking change.
8+
39
* Adding `strata` argument to `ard_categorical_max()`. (#445, @jtalboys)
410

511
* Added function `ard_incidence_rate()` to calculate ARDs for incidence rate estimation. (#234)

R/ard_aod_wald_test.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ ard_aod_wald_test <- function(x, tidy_fun = broom.helpers::tidy_with_broom_or_pa
8585
.data$stat_name %in% "p.value" ~ "p-value",
8686
TRUE ~ .data$stat_name
8787
),
88-
fmt_fn =
88+
fmt_fun =
8989
map(
9090
.data$stat,
9191
function(.x) {

R/ard_car_anova.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ ard_car_anova <- function(x, ...) {
5454
.data$stat_name %in% "p.value" ~ "p-value",
5555
TRUE ~ .data$stat_name
5656
),
57-
fmt_fn =
57+
fmt_fun =
5858
map(
5959
.data$stat,
6060
function(.x) {

R/ard_car_vif.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ ard_car_vif <- function(x, ...) {
8080
"Adjusted GVIF",
8181
.data$stat_name
8282
),
83-
fmt_fn = map(
83+
fmt_fun = map(
8484
.data$stat,
8585
function(.x) {
8686
# styler: off

R/ard_categorical.survey.design.R

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
#' a named list, a list of formulas,
2424
#' or a single formula where the list element is a character vector of
2525
#' statistic names to include. See default value for options.
26-
#' @param fmt_fn ([`formula-list-selector`][cards::syntax])\cr
26+
#' @param fmt_fun ([`formula-list-selector`][cards::syntax])\cr
2727
#' a named list, a list of formulas,
2828
#' or a single formula where the list element is a named list of functions
2929
#' (or the RHS of a formula),
@@ -33,6 +33,7 @@
3333
#' the list element is either a named list or a list of formulas defining the
3434
#' statistic labels, e.g. `everything() ~ list(mean = "Mean", sd = "SD")` or
3535
#' `everything() ~ list(mean ~ "Mean", sd ~ "SD")`.
36+
#' @param fmt_fn `r lifecycle::badge("deprecated")`
3637
#' @inheritParams rlang::args_dots_empty
3738
#'
3839
#' @return an ARD data frame of class 'card'
@@ -47,7 +48,7 @@ ard_categorical.survey.design <- function(data,
4748
by = NULL,
4849
statistic = everything() ~ c("n", "N", "p", "p.std.error", "deff", "n_unweighted", "N_unweighted", "p_unweighted"),
4950
denominator = c("column", "row", "cell"),
50-
fmt_fn = NULL,
51+
fmt_fun = NULL,
5152
stat_label = everything() ~ list(
5253
p = "%",
5354
p.std.error = "SE(%)",
@@ -56,12 +57,23 @@ ard_categorical.survey.design <- function(data,
5657
"N_unweighted" = "Unweighted N",
5758
"p_unweighted" = "Unweighted %"
5859
),
60+
fmt_fn = deprecated(),
5961
...) {
6062
set_cli_abort_call()
6163
check_pkg_installed(pkg = "survey")
6264
check_dots_empty()
6365
deff <- TRUE # we may update in the future to make this an argument for users
6466

67+
# deprecated args ------------------------------------------------------------
68+
if (lifecycle::is_present(fmt_fn)) {
69+
lifecycle::deprecate_soft(
70+
when = "0.2.5",
71+
what = "ard_categorical(fmt_fn)",
72+
with = "ard_categorical(fmt_fun)"
73+
)
74+
fmt_fun <- fmt_fn
75+
}
76+
6577
# process arguments ----------------------------------------------------------
6678
check_not_missing(variables)
6779
cards::process_selectors(
@@ -82,7 +94,7 @@ ard_categorical.survey.design <- function(data,
8294
cards::process_formula_selectors(
8395
data = data$variables[variables],
8496
statistic = statistic,
85-
fmt_fn = fmt_fn,
97+
fmt_fun = fmt_fun,
8698
stat_label = stat_label
8799
)
88100
cards::fill_formula_selectors(
@@ -181,21 +193,21 @@ ard_categorical.survey.design <- function(data,
181193
~ map(.x, as.character)
182194
)
183195
) |>
184-
dplyr::select(-c("stat_label", "fmt_fn", "warning", "error")) |>
196+
dplyr::select(-c("stat_label", "fmt_fun", "warning", "error")) |>
185197
dplyr::mutate(
186198
stat_name =
187199
dplyr::case_match(.data$stat_name, "n" ~ "n_unweighted", "N" ~ "N_unweighted", "p" ~ "p_unweighted")
188200
)
189201
cards <- cards |> dplyr::bind_rows(cards_unweighted) # styler: off
190202
}
191203

192-
# final processing of fmt_fn -------------------------------------------------
204+
# final processing of fmt_fun ------------------------------------------------
193205
cards <- cards |>
194206
.process_nested_list_as_df(
195-
arg = fmt_fn,
196-
new_column = "fmt_fn"
207+
arg = fmt_fun,
208+
new_column = "fmt_fun"
197209
) |>
198-
.default_svy_cat_fmt_fn()
210+
.default_svy_cat_fmt_fun()
199211

200212
# merge in statistic labels --------------------------------------------------
201213
cards <- cards |>
@@ -506,15 +518,15 @@ case_switch <- function(..., .default = NULL) {
506518
return(.default)
507519
}
508520

509-
.default_svy_cat_fmt_fn <- function(x) {
521+
.default_svy_cat_fmt_fun <- function(x) {
510522
x |>
511523
dplyr::mutate(
512-
fmt_fn =
524+
fmt_fun =
513525
pmap(
514-
list(.data$stat_name, .data$stat, .data$fmt_fn),
515-
function(stat_name, stat, fmt_fn) {
516-
if (!is_empty(fmt_fn)) {
517-
return(fmt_fn)
526+
list(.data$stat_name, .data$stat, .data$fmt_fun),
527+
function(stat_name, stat, fmt_fun) {
528+
if (!is_empty(fmt_fun)) {
529+
return(fmt_fun)
518530
}
519531
if (stat_name %in% c("p", "p_miss", "p_nonmiss", "p_unweighted")) {
520532
return(cards::label_round(digits = 1, scale = 100))
@@ -556,7 +568,7 @@ case_switch <- function(..., .default = NULL) {
556568
#'
557569
#' cardx:::.process_nested_list_as_df(ard, NULL, "new_col")
558570
.process_nested_list_as_df <- function(x, arg, new_column, unlist = FALSE) {
559-
# add fmt_fn column if not already present
571+
# add column if not already present
560572
if (!new_column %in% names(x)) {
561573
x[[new_column]] <- list(NULL)
562574
}

R/ard_categorical_ci.survey.design.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ ard_categorical_ci.survey.design <- function(data,
142142
tidyr::unnest("result") |>
143143
dplyr::mutate(
144144
stat_label = .data$stat_name,
145-
fmt_fn = map(.data$stat, ~ case_switch(is.numeric(.x) ~ 2L, .default = as.character))
145+
fmt_fun = map(.data$stat, ~ case_switch(is.numeric(.x) ~ 2L, .default = as.character))
146146
) |>
147147
cards::as_card() |>
148148
cards::tidy_ard_column_order() |>

R/ard_categorical_max.R

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#' calculations. See [cards::ard_categorical()] for more details on specifying denominators.
1818
#' @param quiet (scalar `logical`)\cr
1919
#' Logical indicating whether to suppress additional messaging. Default is `FALSE`.
20+
#' @param fmt_fn `r lifecycle::badge("deprecated")`
2021
#'
2122
#' @return an ARD data frame of class 'card'
2223
#' @name ard_categorical_max
@@ -28,7 +29,7 @@
2829
#' variables = c(AESER, AESEV),
2930
#' id = USUBJID,
3031
#' by = TRTA,
31-
#' denominator = cards::ADSL |> dplyr::rename(TRTA = ARM)
32+
#' denominator = cards::ADSL
3233
#' )
3334
NULL
3435

@@ -41,12 +42,23 @@ ard_categorical_max <- function(data,
4142
statistic = everything() ~ c("n", "p", "N"),
4243
denominator = NULL,
4344
strata = NULL,
44-
fmt_fn = NULL,
45+
fmt_fun = NULL,
4546
stat_label = everything() ~ cards::default_stat_labels(),
4647
quiet = FALSE,
48+
fmt_fn = deprecated(),
4749
...) {
4850
set_cli_abort_call()
4951

52+
# deprecated args ------------------------------------------------------------
53+
if (lifecycle::is_present(fmt_fn)) {
54+
lifecycle::deprecate_soft(
55+
when = "0.2.5",
56+
what = "ard_categorical_max(fmt_fn)",
57+
with = "ard_categorical_max(fmt_fun)"
58+
)
59+
fmt_fun <- fmt_fn
60+
}
61+
5062
# check inputs ---------------------------------------------------------------
5163
check_not_missing(data)
5264
check_not_missing(variables)
@@ -79,7 +91,7 @@ ard_categorical_max <- function(data,
7991
strata = all_of(strata),
8092
statistic = statistic,
8193
denominator = denominator,
82-
fmt_fn = fmt_fn,
94+
fmt_fun = fmt_fun,
8395
stat_label = stat_label
8496
)
8597
}

R/ard_continuous.survey.design.R

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
#' a named list, a list of formulas,
1414
#' or a single formula where the list element is a character vector of
1515
#' statistic names to include. See below for options.
16-
#' @param fmt_fn ([`formula-list-selector`][cards::syntax])\cr
16+
#' @param fmt_fun ([`formula-list-selector`][cards::syntax])\cr
1717
#' a named list, a list of formulas,
1818
#' or a single formula where the list element is a named list of functions
1919
#' (or the RHS of a formula),
@@ -23,6 +23,7 @@
2323
#' the list element is either a named list or a list of formulas defining the
2424
#' statistic labels, e.g. `everything() ~ list(mean = "Mean", sd = "SD")` or
2525
#' `everything() ~ list(mean ~ "Mean", sd ~ "SD")`.
26+
#' @inheritParams ard_categorical.survey.design
2627
#' @inheritParams rlang::args_dots_empty
2728
#'
2829
#' @section statistic argument:
@@ -46,12 +47,23 @@
4647
#' )
4748
ard_continuous.survey.design <- function(data, variables, by = NULL,
4849
statistic = everything() ~ c("median", "p25", "p75"),
49-
fmt_fn = NULL,
50+
fmt_fun = NULL,
5051
stat_label = NULL,
52+
fmt_fn = deprecated(),
5153
...) {
5254
set_cli_abort_call()
5355
check_dots_empty()
5456

57+
# deprecated args ------------------------------------------------------------
58+
if (lifecycle::is_present(fmt_fn)) {
59+
lifecycle::deprecate_soft(
60+
when = "0.2.5",
61+
what = "ard_continuous(fmt_fn)",
62+
with = "ard_continuous(fmt_fun)"
63+
)
64+
fmt_fun <- fmt_fn
65+
}
66+
5567
# check installed packages ---------------------------------------------------
5668
check_pkg_installed(pkg = "survey")
5769

@@ -66,7 +78,7 @@ ard_continuous.survey.design <- function(data, variables, by = NULL,
6678
cards::process_formula_selectors(
6779
data$variables[variables],
6880
statistic = statistic,
69-
fmt_fn = fmt_fn,
81+
fmt_fun = fmt_fun,
7082
stat_label = stat_label
7183
)
7284
cards::fill_formula_selectors(
@@ -128,17 +140,17 @@ ard_continuous.survey.design <- function(data, variables, by = NULL,
128140
}
129141

130142
# add formatting stats -------------------------------------------------------
131-
df_stats$fmt_fn <- list(1L)
132-
if (!is_empty(fmt_fn)) {
143+
df_stats$fmt_fun <- list(1L)
144+
if (!is_empty(fmt_fun)) {
133145
df_stats <-
134146
dplyr::rows_update(
135147
df_stats,
136148
dplyr::tibble(
137-
variable = names(fmt_fn),
138-
stat_name = map(.data$variable, ~ names(fmt_fn[[.x]])),
139-
fmt_fn = map(.data$variable, ~ fmt_fn[[.x]] |> unname())
149+
variable = names(fmt_fun),
150+
stat_name = map(.data$variable, ~ names(fmt_fun[[.x]])),
151+
fmt_fun = map(.data$variable, ~ fmt_fun[[.x]] |> unname())
140152
) |>
141-
tidyr::unnest(cols = c("stat_name", "fmt_fn")),
153+
tidyr::unnest(cols = c("stat_name", "fmt_fun")),
142154
by = c("variable", "stat_name"),
143155
unmatched = "ignore"
144156
)

0 commit comments

Comments
 (0)