Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## Bug Fixes

* Fixed a bug in `get_ard_statistics()` where the `.attributes` argument attached the values of the first columns of the ARD, rather than the values of the columns named in the argument. (#611, @alanahjonas95)

* Fixed a bug in `print.compare_ard()` where the rows present in `x` but not in `y` were announced and then not printed. (#605, @malanbos)

* `print.compare_ard()` now prints its tables through the ARD print method rather than coercing them with `as.data.frame()`. Scalar list-column values (e.g. `group1_level`, `variable_level`, `stat`) are shown rather than collapsed, and long tables are truncated with the withheld row count reported in the footer. (#605)
Expand Down
2 changes: 1 addition & 1 deletion R/get_ard_statistics.R
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ get_ard_statistics <- function(x,
#' cards:::.create_list_for_attributes(ard, c("group1", "group1_level"), 1)
.create_list_for_attributes <- function(ard_subset, attributes, i) {
ret <- list()
for (attr in seq_along(attributes)) {
for (attr in attributes) {
ret <- c(ret, list(ard_subset[[attr]][[i]]))
}
stats::setNames(ret, nm = attributes)
Expand Down
20 changes: 7 additions & 13 deletions tests/testthat/_snaps/get_ard_statistics.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,27 +18,21 @@

Code
get_ard_statistics(ard, group1_level %in% "Placebo", variable_level %in%
"65-80", .attributes = c("warning", "error"))
"65-80", .attributes = "stat_label")
Output
$n
[1] 42
attr(,"warning")
[1] "ARM"
attr(,"error")
[1] "Placebo"
attr(,"stat_label")
[1] "n"

$N
[1] 86
attr(,"warning")
[1] "ARM"
attr(,"error")
[1] "Placebo"
attr(,"stat_label")
[1] "N"

$p
[1] 0.4883721
attr(,"warning")
[1] "ARM"
attr(,"error")
[1] "Placebo"
attr(,"stat_label")
[1] "%"


18 changes: 17 additions & 1 deletion tests/testthat/test-get_ard_statistics.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,23 @@ test_that("get_ard_statistics() works", {
ard,
group1_level %in% "Placebo",
variable_level %in% "65-80",
.attributes = c("warning", "error")
.attributes = "stat_label"
)
)

# attributes are taken from the requested columns, not by column position
expect_equal(
get_ard_statistics(
ard,
group1_level %in% "Placebo",
variable_level %in% "65-80",
.attributes = c("stat_label", "stat_name")
) |>
lapply(attributes),
list(
n = list(stat_label = "n", stat_name = "n"),
N = list(stat_label = "N", stat_name = "N"),
p = list(stat_label = "%", stat_name = "p")
)
)
})
Loading