Skip to content

Commit 25ffce6

Browse files
kieranjmartinMelkiadesddsjoberg
authored
Make as card check format (#534)
Resolves #514 Incorportating `check_ard_structure` into `as_card` proved to not be straight forwards as `as_card` is used throughout the code base to coerce objects into a card class that do not pass the checks in `check_ard_structure`. For now at least I did the following 1) `check_ard_structure` can either error or warn based on user input. I made a function to switch between these (I couldn't see any function which existed to do this already). Part of me wonders about allowing the user a bit more control over what it considers an error or a warning; they can switch off caring about the column order, and whether there is a methods entry, but maybe we could allow more in future. That said I think it's probably better as a binary switch for a change 2) In `as_card`, there is now an argument for whether you want to check if a card follows this structure. At the moment this defaults to TRUE, but if you think this is too strong I could switch it to default FALSE. Doing that would be the most low impact change. --------- Signed-off-by: Kieran Martin <kieranjmartin@gmail.com> Co-authored-by: Davide Garolini <davide.garolini@roche.com> Co-authored-by: Davide Garolini <dgarolini@gmail.com> Co-authored-by: Daniel Sjoberg <danield.sjoberg@gmail.com>
1 parent f390ae2 commit 25ffce6

29 files changed

+347
-44
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: cards
22
Title: Analysis Results Data
3-
Version: 0.7.1.9004
3+
Version: 0.7.1.9005
44
Authors@R: c(
55
person("Daniel D.", "Sjoberg", , "danield.sjoberg@gmail.com", role = c("aut", "cre"),
66
comment = c(ORCID = "0000-0003-0862-2018")),

NEWS.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1-
# cards 0.7.1.9004
1+
# cards 0.7.1.9005
22

33
* Adding `ard_tabulate_rows()` function to tabulate the number of rows in a data frame. (#531)
44

55
* Users are now messaged if the `by` or `strata` arguments pass columns with different classes in the `ard_tabulate(data,denominator)` arguments as this _may_ cause issues downstream. (#515)
66

7+
* `as_card` now has the argument `check = TRUE` which when `TRUE` will confirm if the data frame being converted matches the cards spec using `check_ard_structure`. To support this, `check_ard_structure` has a new argument `error_on_fail` which is FALSE by default. When TRUE any failures will generate an error. (#514)
8+
9+
710
# cards 0.7.1
811

912
* Updated `ard_stack_hierarchical()` so that the `denominator` dataset only contains the `id` and `by` variables. (#482)

R/ard_attributes.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ ard_attributes.data.frame <- function(data,
5454

5555
# return empty ARD if no variables selected ----------------------------------
5656
if (is_empty(variables)) {
57-
return(dplyr::tibble() |> as_card())
57+
return(dplyr::tibble() |> as_card(check = FALSE))
5858
}
5959

6060

R/ard_formals.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,5 +46,5 @@ ard_formals <- function(fun, arg_names, passed_args = list(),
4646
# put formals list in ARD structure ------------------------------------------
4747
enframe(lst_args[arg_names], "stat_name", "stat") |>
4848
dplyr::mutate(stat_label = .data$stat_name, .after = "stat_name") |>
49-
as_card()
49+
as_card(check = FALSE)
5050
}

R/ard_hierarchical.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ ard_hierarchical.data.frame <- function(data,
114114

115115
# return empty ARD if no variables selected ----------------------------------
116116
if (is_empty(variables)) {
117-
return(dplyr::tibble() |> as_card())
117+
return(dplyr::tibble() |> as_card(check = FALSE))
118118
}
119119

120120
# if denominator doesn't have all by, they need to be added ------------------
@@ -192,7 +192,7 @@ ard_hierarchical_count.data.frame <- function(data,
192192

193193
# return empty ARD if no variables selected ----------------------------------
194194
if (is_empty(variables)) {
195-
return(dplyr::tibble() |> as_card())
195+
return(dplyr::tibble() |> as_card(check = FALSE))
196196
}
197197

198198
# add dummy variable for counting --------------------------------------------
@@ -210,7 +210,7 @@ ard_hierarchical_count.data.frame <- function(data,
210210
) |>
211211
.rename_last_group_as_variable(by = by, variables = variables) |>
212212
dplyr::mutate(context = "hierarchical_count") |>
213-
as_card()
213+
as_card(check = FALSE)
214214
}
215215

216216
#' Rename Last Group to Variable

R/ard_missing.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ ard_missing.data.frame <- function(data,
5858

5959
# return empty ARD if no variables selected ----------------------------------
6060
if (is_empty(variables)) {
61-
return(dplyr::tibble() |> as_card())
61+
return(dplyr::tibble() |> as_card(check = FALSE))
6262
}
6363

6464
# convert all variables to T/F whether it's missing --------------------------

R/ard_mvsummary.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ ard_mvsummary.data.frame <- function(data,
9191

9292
# return empty ARD if no variables selected ----------------------------------
9393
if (is_empty(variables)) {
94-
return(dplyr::tibble() |> as_card())
94+
return(dplyr::tibble() |> as_card(check = FALSE))
9595
}
9696

9797
missing_statistics_vars <- setdiff(variables, names(statistic))

R/ard_stack_hierarchical.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,7 @@ internal_stack_hierarchical <- function(
517517
}
518518

519519
# return final result --------------------------------------------------------
520-
result |> as_card()
520+
result |> as_card(check = FALSE)
521521
}
522522

523523
# this function calculates either the counts or the rates of the events

R/ard_strata.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,6 @@ ard_strata <- function(.data, .by = NULL, .strata = NULL, .f, ...) {
111111
# unnest ard data frame and return final table -------------------------------
112112
df_nested_data |>
113113
tidyr::unnest(cols = all_of("ard")) |>
114-
as_card() |>
114+
as_card(check = FALSE) |>
115115
tidy_ard_column_order(group_order = "descending")
116116
}

R/ard_summary.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ ard_summary.data.frame <- function(data,
127127

128128
# return empty ARD if no variables selected ----------------------------------
129129
if (is_empty(variables)) {
130-
return(dplyr::tibble() |> as_card())
130+
return(dplyr::tibble() |> as_card(check = FALSE))
131131
}
132132

133133

@@ -187,7 +187,7 @@ ard_summary.data.frame <- function(data,
187187
dplyr::mutate(context = "summary") |>
188188
tidy_ard_column_order() |>
189189
tidy_ard_row_order() |>
190-
as_card()
190+
as_card(check = FALSE)
191191
}
192192

193193

0 commit comments

Comments
 (0)