Skip to content
Open
Show file tree
Hide file tree
Changes from 6 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
170 changes: 170 additions & 0 deletions .Rhistory
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
Sys.getenv()
library(cards)
library(gtsummary)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we need to add this to .gitignore

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(the file)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh my goodness! can you add, please? I am surprised it wasn't already there! 😱

ard <- ard_tabulate(
data = cards::ADAE,
variables = c(AESOC, AEDECOD),
denominator = cards::ADSL
)
ae_tbl <- tbl_ard_summary(
ard,
by = TRTA
)
ard <- ard_tabulate(
data = cards::ADAE,
by = TRTA
variables = c(AESOC, AEDECOD),
ard <- ard_tabulate(
data = cards::ADAE,
by = TRTA,
variables = c(AESOC, AEDECOD),
denominator = cards::ADSL
)
ae_tbl <- tbl_ard_summary(
ard,
by = TRTA
)
ae_tbl
ae_tbl <- tbl_ard_summary(
ard,
by = TRTA,
statistic = "{n} (p)}"
)
ae_tbl <- tbl_ard_summary(
ard,
by = TRTA,
statistic = "{n} ({p})"
)
ae_tbl <- tbl_ard_summary(
ard,
by = TRTA,
statistic = list(all_categorical() ~ "{n} ({p})")
)
ae_tbl
ae_tbl <- tbl_ard_summary(
ard,
by = TRTA,
statistic = list(all_categorical() ~ "{n} ({p})")
) |>
sort_ard_hierarchical()
ard <- ard_tabulate(
data = cards::ADAE,
by = TRTA,
variables = c(AESOC, AEDECOD),
denominator = cards::ADSL
) |>
sort_ard_hierarchical()
ard <- ard_stack_hierarchical(
data = cards::ADAE,
by = TRTA,
variables = c(AESOC, AEDECOD),
denominator = cards::ADSL,
id = USUBJID
) |>
sort_ard_hierarchical()
ae_tbl <- tbl_ard_summary(
ard,
by = TRTA,
statistic = list(all_categorical() ~ "{n} ({p})")
)
ae_tbl <- tbl_ard_hierarchical(
ard,
by = TRTA,
statistic = list(all_categorical() ~ "{n} ({p})")
)
ae_tbl <- tbl_ard_hierarchical(
ard,
by = TRTA,
variables = c(AESOC, AEDECOD),
statistic = list(all_categorical() ~ "{n} ({p})")
)
ae_tbl
ard <- ard_stack_hierarchical(
data = cards::ADAE,
by = TRTA,
variables = c(AESOC, AEDECOD),
denominator = cards::ADSL,
statistic = list(all_categorical() ~ "{n} ({p})"),
id = USUBJID
) |>
sort_ard_hierarchical()
ae_tbl <- tbl_ard_hierarchical(
ard,
by = TRTA,
variables = c(AESOC, AEDECOD),
statistic = list(all_categorical() ~ "{n} ({p})")
)
ae_tbl
ard <- ard_stack_hierarchical(
data = cards::ADAE,
by = TRTA,
variables = c(AESOC, AEDECOD),
denominator = cards::ADSL,
id = USUBJID
) |>
sort_ard_hierarchical()
ae_tbl <- tbl_ard_hierarchical(
ard,
by = TRTA,
variables = c(AESOC, AEDECOD)
)
ae_tbl
devtools::load_all()
getwd()
setwd("D:/ARDs/cards")
getwd()
devtools::load_all()
ard <- ard_stack_hierarchical(
data = cards::ADAE,
by = TRTA,
variables = c(AESOC, AEDECOD),
denominator = cards::ADSL,
statistic = list(all_categorical() ~ "{n} ({p})"),
id = USUBJID
) |>
sort_ard_hierarchical()
ADSL
table(ADSL$TRTA)
ard <- ard_stack_hierarchical(
data = cards::ADAE,
by = TRTA,
variables = c(AESOC, AEDECOD),
denominator = cards::ADSL,
statistic = list(all_categorical() ~ "{n} ({p})"),
id = USUBJID
) |>
sort_ard_hierarchical(sort_col = Placebo)
ard <- ard_stack_hierarchical(
data = cards::ADAE,
by = TRTA,
variables = c(AESOC, AEDECOD),
denominator = cards::ADSL,
statistic = list(all_categorical() ~ "{n} ({p})"),
id = USUBJID
) |>
sort_ard_hierarchical(sort_col = 'Placebo')
ae_tbl <- tbl_ard_hierarchical(
ard,
by = TRTA,
variables = c(AESOC, AEDECOD)
)
ae_tbl
ard <- ard_stack_hierarchical(
data = cards::ADAE,
by = TRTA,
variables = c(AESOC, AEDECOD),
denominator = cards::ADSL,
statistic = list(all_categorical() ~ "{n} ({p})"),
id = USUBJID
) |>
sort_ard_hierarchical(sort_col = 'Xanomeline High Dose')
ae_tbl <- tbl_ard_hierarchical(
ard,
by = TRTA,
variables = c(AESOC, AEDECOD)
)
ae_tbl
devtools::check()
devtools::install_dev_deps()
devtools::check()
devtools::test_coverage()
31 changes: 28 additions & 3 deletions R/sort_ard_hierarchical.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
#' sums, otherwise `p` is used. If neither `n` nor `p` are present in `x` for the variable, an error will occur.
#'
#' Defaults to `everything() ~ "descending"`.
#' @param sort_col \cr
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

after the argument name, we put the expected type of input. maybe that is causing your latex issue

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay,thanks for the hint.

#' specify the name of the treatment column you want to sort by, or leave it blank to sort by the sum
#' across all treatment columns.
#'
#' @return an ARD data frame of class 'card'
#' @seealso [filter_ard_hierarchical()]
Expand Down Expand Up @@ -51,11 +54,19 @@
#' denominator = ADSL
#' ) |>
#' sort_ard_hierarchical(sort = list(AESOC ~ "alphanumeric", AEDECOD ~ "descending"))
#'
#' ard_stack_hierarchical_count(
#' ADAE,
#' variables = c(AESOC, AEDECOD),
#' by = TRTA,
#' denominator = ADSL
#' ) |>
#' sort_ard_hierarchical(sort_col = "Placebo")
NULL

#' @rdname sort_ard_hierarchical
#' @export
sort_ard_hierarchical <- function(x, sort = everything() ~ "descending") {
sort_ard_hierarchical <- function(x, sort = everything() ~ "descending", sort_col = NULL) {
set_cli_abort_call()

# check and process inputs ---------------------------------------------------------------------
Expand Down Expand Up @@ -156,7 +167,7 @@ sort_ard_hierarchical <- function(x, sort = everything() ~ "descending") {
# descending sort
x_sort <- x_sort |>
# calculate sums for each group at the current level, then get group indices
.append_hierarchy_sums(ard_args, cols, i)
.append_hierarchy_sums(ard_args, cols, i, sort_col)
} else {
# alphanumeric sort
x_sort <- x_sort |>
Expand Down Expand Up @@ -248,7 +259,7 @@ sort_ard_hierarchical <- function(x, sort = everything() ~ "descending") {
}

# this function calculates and appends group sums/ordering for the current hierarchy level (across `by` variables)
.append_hierarchy_sums <- function(x, ard_args, cols, i) {
.append_hierarchy_sums <- function(x, ard_args, cols, i, sort_col = sort_col) {
cur_var <- names(cols)[i] # get current grouping variable
next_var <- names(cols)[i + 1] # get next grouping variable

Expand All @@ -275,6 +286,20 @@ sort_ard_hierarchical <- function(x, sort = everything() ~ "descending") {
sort_stat <- if (n_stat) "n" else "p" # statistic used to calculate group sums

# calculate group sums

# Introduced the ability to sort the ARD based on a particular treatment column

if (!is.null(sort_col)) {
x <- x |>
dplyr::mutate(stat = dplyr::case_when(
stat_name == sort_stat & variable == dplyr::last(ard_args$variables) & group1_level == sort_col ~ stat,
stat_name == sort_stat & variable == dplyr::last(ard_args$variables) & group1_level != sort_col ~ list(0),
TRUE ~ stat
))
} else {
x <- x
}

sum_i <- paste0("sum_group_", i) # sum column label
x_sums <- x |>
dplyr::filter(
Expand Down
14 changes: 13 additions & 1 deletion man/sort_ard_hierarchical.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading