Skip to content
Merged
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
23 changes: 12 additions & 11 deletions R/ae_forestly.R
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
#' format_ae_forestly() |>
#' ae_forestly()
#' }

ae_forestly <- function(outdata,
display_soc_toggle = TRUE,
filter = c("prop", "n"),
Expand Down Expand Up @@ -90,8 +89,9 @@ ae_forestly <- function(outdata,

if (is.null(filter_label)) {
filter_label <- ifelse(filter == "prop",
"Incidence (%) in One or More Treatment Groups",
"Number of AE in One or More Treatment Groups")
"Incidence (%) in One or More Treatment Groups",
"Number of AE in One or More Treatment Groups"
)
}

# `max_page` controls the maximum page number displayed in the interactive forest table.
Expand All @@ -108,13 +108,15 @@ ae_forestly <- function(outdata,
FUN.VALUE = character(1)
)

for (par in parameters[(!(parameters %in% unique(outdata$parameter_order)))]){
for (par in parameters[(!(parameters %in% unique(outdata$parameter_order)))]) {
outdata$tbl <-
rbind(outdata$tbl, NA)
outdata$tbl$name <- ifelse(is.na(outdata$tbl$name), "No data to display", outdata$tbl$name)
outdata$tbl$parameter <-
factor(ifelse(is.na(outdata$tbl$parameter), par, as.character(outdata$tbl$parameter)),
levels(outdata$parameter_order))
factor(
ifelse(is.na(outdata$tbl$parameter), par, as.character(outdata$tbl$parameter)),
levels(outdata$parameter_order)
)
}

outdata$tbl$parameter <- factor(
Expand Down Expand Up @@ -191,8 +193,8 @@ ae_forestly <- function(outdata,
outdata$ae_listing,
((toupper(outdata$ae_listing$Adverse_Event) %in% toupper(t_row)) &
(outdata$ae_listing$param == t_param)) |
((toupper(outdata$ae_listing$SOC_Name) %in% toupper(t_row)) &
(outdata$ae_listing$param == t_param))
((toupper(outdata$ae_listing$SOC_Name) %in% toupper(t_row)) &
(outdata$ae_listing$param == t_param))
)

# Exclude 'param' column from t_details
Expand All @@ -217,9 +219,9 @@ ae_forestly <- function(outdata,
col_defs <- stats::setNames(
lapply(names(t_details), function(name) {
# Use label from the list
label_name <- if(is.null(labels[[name]])) name else labels[[name]][[1]]
label_name <- if (is.null(labels[[name]])) name else labels[[name]][[1]]
reactable::colDef(
header = label_name, # Use header instead of name
header = label_name, # Use header instead of name
cell = function(value) format(value, nsmall = 1),
align = "center",
minWidth = 70
Expand All @@ -242,7 +244,6 @@ ae_forestly <- function(outdata,
highlight = TRUE
)
},

pageSizeOptions = max_page,

# Default sort variable
Expand Down
15 changes: 7 additions & 8 deletions R/ae_listing.R
Original file line number Diff line number Diff line change
Expand Up @@ -208,9 +208,9 @@ format_ae_listing <- function(outdata, display_unique_records = FALSE) {
}
attr(res[["Participant_ID"]], "label") <- NULL

res[["Gender"]] <- titlecase(res[["SEX"]])
res[["Gender"]] <- tools::toTitleCase(res[["SEX"]])

res[["Race"]] <- titlecase(res[["RACE"]])
res[["Race"]] <- tools::toTitleCase(tolower(res[["RACE"]]))

res[["Age"]] <- res[["AGE"]]

Expand All @@ -220,10 +220,9 @@ format_ae_listing <- function(outdata, display_unique_records = FALSE) {

# Onset epoch
if ("EPOCH" %in% toupper(names(res))) {
res[["Onset_Epoch"]] <- titlecase(res[["EPOCH"]])
res[["Onset_Epoch"]] <- tools::toTitleCase(tolower(res[["EPOCH"]])) # propcase the EPOCH
}


# Relative day of onset (ASTDY)
if ("ASTDY" %in% toupper(names(res))) {
res[["Relative_Day_of_Onset"]] <- res[["ASTDY"]]
Expand All @@ -239,7 +238,7 @@ format_ae_listing <- function(outdata, display_unique_records = FALSE) {
# Duration
if ("ADURN" %in% toupper(names(res)) & "ADURU" %in% toupper(names(res))) {
res[["Duration"]] <- paste(ifelse(is.na(res[["ADURN"]]), "", as.character(res[["ADURN"]])),
titlecase(res[["ADURU"]]),
tools::toTitleCase(tolower(res[["ADURU"]])),
sep = " "
) # AE duration with unit

Expand Down Expand Up @@ -275,7 +274,7 @@ format_ae_listing <- function(outdata, display_unique_records = FALSE) {
# AE related
if ("AEREL" %in% toupper(names(res))) {
res[["Related"]] <- ifelse(res[["AEREL"]] == "RELATED", "Y", ifelse(
toupper(res[["AEREL"]]) == "NOT RELATED", "N", titlecase(res[["AEREL"]])
toupper(res[["AEREL"]]) == "NOT RELATED", "N", tools::toTitleCase(tolower(res[["AEREL"]]))
))
}

Expand All @@ -290,7 +289,7 @@ format_ae_listing <- function(outdata, display_unique_records = FALSE) {
"DOSE INCREASED" = "Increased",
"NOT APPLICABLE" = "N/A",
"UNKNOWN" = "Unknown",
titlecase(res[["AEACN"]][i])
tools::toTitleCase(tolower(res[["AEACN"]][i]))
)
}
} else {
Expand All @@ -307,7 +306,7 @@ format_ae_listing <- function(outdata, display_unique_records = FALSE) {
"RECOVERING/RESOLVING" = "Resolving",
"RECOVERED/RESOLVED WITH SEQUELAE" = "Sequelae",
"NOT RECOVERED/NOT RESOLVED" = "Not Resolved",
titlecase(res[["AEOUT"]][i])
tools::toTitleCase(tolower(res[["AEOUT"]][i]))
)
}
} else {
Expand Down
16 changes: 9 additions & 7 deletions R/format_ae_forestly.R
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,13 @@
#' @export
#'
#' @examples
#' adsl <- forestly_adsl[1:100,]
#' adae <- forestly_adae[1:100,]
#' adsl <- forestly_adsl[1:100, ]
#' adae <- forestly_adae[1:100, ]
#' meta_forestly(
#' dataset_adsl = adsl,
#' dataset_adae = adae
#' ) |>
#' prepare_ae_forestly()|>
#' prepare_ae_forestly() |>
#' format_ae_forestly()
format_ae_forestly <- function(
outdata,
Expand Down Expand Up @@ -158,7 +158,7 @@ format_ae_forestly <- function(
fig_prop_range <- round(range(tbl_prop, na.rm = TRUE) + c(-2, 2))
} else {
if (prop_range[1] > range(tbl_prop, na.rm = TRUE)[1] |
prop_range[2] < range(tbl_prop, na.rm = TRUE)[2]) {
prop_range[2] < range(tbl_prop, na.rm = TRUE)[2]) {
warning("There are data points outside the specified range for proportion.")
}
fig_prop_range <- prop_range
Expand Down Expand Up @@ -204,7 +204,7 @@ format_ae_forestly <- function(
fig_diff_range <- round(range(tbl_diff, na.rm = TRUE) + c(-2, 2))
} else {
if (diff_range[1] > range(tbl_diff, na.rm = TRUE)[1] |
diff_range[2] < range(tbl_diff, na.rm = TRUE)[2]) {
diff_range[2] < range(tbl_diff, na.rm = TRUE)[2]) {
warning("There are data points outside the specified range for difference.")
}
fig_diff_range <- diff_range
Expand Down Expand Up @@ -369,14 +369,16 @@ format_ae_forestly <- function(
)

# column hidden
columns <- lapply(columns, function (x) {
columns <- lapply(columns, function(x) {
if (!"show" %in% names(x)) {
x$show <- TRUE
}
return(x)
})

hidden_item <- names(columns)[(!names(columns) %in% "soc_name") & (sapply(columns, function(x) {return(!x$show)}))]
hidden_item <- names(columns)[(!names(columns) %in% "soc_name") & (sapply(columns, function(x) {
return(!x$show)
}))]

# Create outdata
outdata$tbl <- tbl
Expand Down
36 changes: 18 additions & 18 deletions R/prepare_ae_forestly.R
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
#' @export
#'
#' @examples
#' adsl <- forestly_adsl[1:100,]
#' adae <- forestly_adae[1:100,]
#' adsl <- forestly_adsl[1:100, ]
#' adae <- forestly_adae[1:100, ]
#' meta_forestly(
#' dataset_adsl = adsl,
#' dataset_adae = adae
Expand All @@ -48,8 +48,6 @@ prepare_ae_forestly <- function(
"AEREL", "AEACN", "AEOUT", "ADURN", "ADURU"
),
ae_listing_unique = FALSE) {


if (is.null(population)) {
if (length(meta$population) == 1) {
population <- meta$population[[1]]$name
Expand All @@ -66,32 +64,32 @@ prepare_ae_forestly <- function(
}
}

if( is.null(parameter)){
if (is.null(parameter)) {
parameters <- names(meta$parameter)

meta$parameter
}else{
} else {
parameters <- unlist(strsplit(parameter, ";"))
}

for(i in seq_along(parameters)){
for (i in seq_along(parameters)) {
para <- meta$parameter[[parameters[i]]]
if(is.null(para$var)){
if (is.null(para$var)) {
para$var <- "AEDECOD"
}
if(is.null(para$soc)){
if (is.null(para$soc)) {
para$soc <- "AEBODSYS"
}
if(is.null(para$seq)){
if (is.null(para$seq)) {
para$seq <- sample(1e5:2e5, size = 1)
}
if(is.null(para$term1)){
if (is.null(para$term1)) {
para$term1 <- ""
}
if(is.null(para$term2)){
if (is.null(para$term2)) {
para$term2 <- ""
}
if(is.null(para$summ_row)){
if (is.null(para$summ_row)) {
para$summ_row <- ""
}
meta$parameter[[parameters[i]]] <- para
Expand All @@ -112,7 +110,7 @@ prepare_ae_forestly <- function(

ae_listing <- data.frame()
for (i in 1:length(res)) {
if (nrow(res[[i]]$ae_listing) > 0){
if (nrow(res[[i]]$ae_listing) > 0) {
res[[i]]$ae_listing$param <- res[[i]]$parameter
ae_listing <- rbind(ae_listing, res[[i]]$ae_listing)
}
Expand Down Expand Up @@ -151,10 +149,12 @@ prepare_ae_forestly <- function(
parameter_order <- factor(parameter_order, levels = parameters)

# Display message if a specified-parameter is not included
if (any(!(parameters %in% unique(parameter_order)))){
warning(paste0('There is no record for the parameter "',
parameters[!(parameters %in% unique(parameter_order))],
'" to display.'))
if (any(!(parameters %in% unique(parameter_order)))) {
warning(paste0(
'There is no record for the parameter "',
parameters[!(parameters %in% unique(parameter_order))],
'" to display.'
))
}

# Additional group information
Expand Down
22 changes: 12 additions & 10 deletions R/reactable2.R
Original file line number Diff line number Diff line change
Expand Up @@ -111,16 +111,18 @@ reactable2 <- function(
)

if (soc_toggle) {
on_click2 <- paste0("function control_column(hidden_columns) {",
" if (hidden_columns.includes('soc_name')) {",
" Reactable.setHiddenColumns('", element_id, "', prevColumns => {
return prevColumns.length === 0 ? ['soc_name']:[", hidden_item ,"]})",
" } else {",
" Reactable.setHiddenColumns('", element_id, "', prevColumns => {
return prevColumns.length === 0 ? [ ]: ['soc_name',", hidden_item, "]})",
" }",
"}",
"control_column(Reactable.getState('", element_id, "').hiddenColumns);")
on_click2 <- paste0(
"function control_column(hidden_columns) {",
" if (hidden_columns.includes('soc_name')) {",
" Reactable.setHiddenColumns('", element_id, "', prevColumns => {
return prevColumns.length === 0 ? ['soc_name']:[", hidden_item, "]})",
" } else {",
" Reactable.setHiddenColumns('", element_id, "', prevColumns => {
return prevColumns.length === 0 ? [ ]: ['soc_name',", hidden_item, "]})",
" }",
"}",
"control_column(Reactable.getState('", element_id, "').hiddenColumns);"
)

tbl <- htmltools::tagList(
htmltools::tags$button(
Expand Down
27 changes: 15 additions & 12 deletions data-raw/forestly_adae.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,22 @@ adae <- r2rtf::r2rtf_adae


# Derive AREL from existing AEREL
adae <- adae %>% filter(TRTA!="Xanomeline High Dose") %>%
adae <- adae %>%
filter(TRTA != "Xanomeline High Dose") %>%
mutate(AREL = case_when(
AEREL %in% c("PROBABLE", "POSSIBLE") ~ "RELATED",
AEREL %in% c("NONE", "REMOTE", "") ~ "NOT RELATED",
TRUE ~ AEREL # Keep original AREL if none of the conditions are met
TRUE ~ AEREL # Keep original AREL if none of the conditions are met
))


freq <- adae %>% count(AREL, AEREL) %>%
freq <- adae %>%
count(AREL, AEREL) %>%
arrange(desc(n))
print(freq)

freq2 <- forestly_adae %>% count(AREL, AEREL) %>%
freq2 <- forestly_adae %>%
count(AREL, AEREL) %>%
arrange(desc(n))
print(freq2)

Expand All @@ -39,17 +42,17 @@ adae$AEACN <- sample(

for (i in seq_along(adae$AEACN)) {
adae$action_taken[i] <- switch(adae$AEACN[i],
"DOSE NOT CHANGED" = "None",
"DRUG INTERRUPTED" = "Interrupted",
"DRUG WITHDRAWN" = "Discontinued",
"NOT APPLICABLE" = "N/A",
"UNKNOWN" = "Unknown",
"''" = "None",
tools::toTitleCase(tolower(adae$AEACN[i]))
"DOSE NOT CHANGED" = "None",
"DRUG INTERRUPTED" = "Interrupted",
"DRUG WITHDRAWN" = "Discontinued",
"NOT APPLICABLE" = "N/A",
"UNKNOWN" = "Unknown",
"''" = "None",
tools::toTitleCase(tolower(adae$AEACN[i]))
)
}

#CHECKS
# CHECKS
# freq <- adae %>% count(AEACN) %>% arrange(desc(n))
# print(freq)
#
Expand Down
6 changes: 3 additions & 3 deletions man/format_ae_forestly.Rd

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

4 changes: 2 additions & 2 deletions man/prepare_ae_forestly.Rd

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

Loading
Loading