Skip to content

Commit

Permalink
Merge pull request #155 from SafetyGraphics/dev
Browse files Browse the repository at this point in the history
v0.4.0
  • Loading branch information
nandriychuk authored Sep 20, 2024
2 parents c73cb33 + 65190c6 commit fce6b3c
Show file tree
Hide file tree
Showing 150 changed files with 8,753 additions and 498 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
steps:
- uses: actions/checkout@v2
- uses: r-lib/actions/setup-r@v1
- uses: r-lib/actions/setup-r@v2
- name: Install dependencies
run: |
install.packages(c("remotes", "rcmdcheck"))
Expand Down
8 changes: 6 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: safetyCharts
Title: Charts for Monitoring Clinical Trial Safety
Version: 0.3.0
Version: 0.4.0
Authors@R:
person(
given = "Jeremy",
Expand All @@ -15,16 +15,18 @@ BugReports: https://github.com/SafetyGraphics/safetyCharts/issues
License: MIT + file LICENSE
Encoding: UTF-8
LazyData: true
RoxygenNote: 7.1.2
RoxygenNote: 7.2.3
Roxygen: list(markdown = TRUE)
Imports:
dplyr,
DT,
forcats,
ggplot2,
htmltools,
htmlwidgets,
huxtable,
jsonlite,
magrittr,
pharmaRTF,
plotly,
purrr,
Expand All @@ -33,6 +35,8 @@ Imports:
shiny,
stringr,
Tendril,
tibble,
tidyr,
Tplyr
Suggests:
testthat,
Expand Down
30 changes: 28 additions & 2 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,33 +1,50 @@
# Generated by roxygen2: do not edit by hand

export("%>%")
export(QT_OutlierExplorer_server)
export(QT_OutlierExplorer_ui)
export(QT_Outlier_Explorer)
export(aeExplorer)
export(demogRTF_server)
export(demogRTF_table)
export(demogRTF_ui)
export(hepExplorer)
export(init_aeExplorer)
export(init_aeTimelines)
export(init_cmExplorer)
export(init_mhExplorer)
export(init_paneledOutlierExplorer)
export(init_safetyOutlierExplorer)
export(init_safetyResultsOverTime)
export(init_safetyShiftPlot)
export(lab_distribution_server)
export(lab_distribution_ui)
export(paneledOutlierExplorer)
export(render_widget)
export(safetyOutlierExplorer_server)
export(safetyOutlierExplorer_ui)
export(safety_outlier_explorer)
export(safety_results_over_time)
export(stack_events)
export(standardize_events)
export(tendril_chart)
import(Tendril)
import(Tplyr)
import(dplyr)
import(ggplot2)
import(htmlwidgets)
import(rlang)
import(shiny)
importFrom(DT,DTOutput)
importFrom(DT,renderDT)
importFrom(RColorBrewer,brewer.pal)
importFrom(Tendril,Tendril)
importFrom(dplyr,left_join)
importFrom(dplyr,select)
importFrom(forcats,fct_drop)
importFrom(forcats,fct_reorder)
importFrom(htmltools,br)
importFrom(htmltools,div)
importFrom(htmlwidgets,createWidget)
importFrom(htmlwidgets,sizingPolicy)
importFrom(huxtable,as_hux)
importFrom(huxtable,set_align)
importFrom(huxtable,set_bold)
Expand All @@ -37,19 +54,28 @@ importFrom(huxtable,set_escape_contents)
importFrom(huxtable,set_valign)
importFrom(huxtable,set_width)
importFrom(jsonlite,toJSON)
importFrom(magrittr,"%>%")
importFrom(pharmaRTF,add_footnotes)
importFrom(pharmaRTF,add_titles)
importFrom(pharmaRTF,hf_line)
importFrom(pharmaRTF,rtf_doc)
importFrom(pharmaRTF,set_column_header_buffer)
importFrom(pharmaRTF,set_font_size)
importFrom(pharmaRTF,set_ignore_cell_padding)
importFrom(pharmaRTF,write_rtf)
importFrom(plotly,animation_slider)
importFrom(plotly,layout)
importFrom(plotly,plot_ly)
importFrom(plotly,plotlyOutput)
importFrom(plotly,renderPlotly)
importFrom(purrr,imap)
importFrom(purrr,list_modify)
importFrom(purrr,map)
importFrom(rlang,.data)
importFrom(rlang,set_names)
importFrom(rlang,sym)
importFrom(stats,setNames)
importFrom(stringr,str_detect)
importFrom(tibble,as_tibble)
importFrom(tidyr,unite)
importFrom(utils,hasName)
11 changes: 5 additions & 6 deletions R/QT_Outlier_Explorer.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,17 @@
#'
#' @return returns a chart object
#'
#' @import dplyr
#' @importFrom plotly plot_ly animation_slider layout
#' @import rlang
#' @importFrom rlang .data
#' @import dplyr
#'
#' @export




QT_Outlier_Explorer <- function(data, settings)
{
QT_Outlier_Explorer <- function(
data,
settings
) {

# horizontal reference line
hline <- function(y = 0, color = "blue") {
Expand Down
97 changes: 97 additions & 0 deletions R/aeExplorer.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
#' Make standalone aeExplorer html widget
#'
#' Convience mapping of render_widget for aeExplorer.
#'
#' The [data](https://github.com/RhoInc/aeexplorer/wiki/Data-Guidelines) and
#' [mapping](https://github.com/RhoInc/aeexplorer/wiki/Configuration) should match the specs
#' described in the [aeExplorer](https://github.com/RhoInc/aeexplorer/wiki/Configuration)
#' JavaScript library. Items passed in ... are added to mapping, and then the list is converted to
#' JSON via `jsonlite::toJSON(mapping, auto_unbox=TRUE, NULL="NULL")`.
#'
#' The default mapping shown below is designed to work with data in the CDISC ADaM format (like
#' `safetydata::adam_adlbc`).
#'
#' ```
#' mapping <- list(
#' dm = list(
#' id_col = 'USUBJID',
#' treatment_col = 'ARM'
#' ),
#' aes = list(
#' id_col = 'USUBJID',
#' bodsys_col = 'AEBODSYS',
#' term_col = 'AEDECOD'
#' )
#' )
#' ```
#'
#' Parameters that are not included in the default mapping can be accessed via ....
#'
#' For more options see the [full specs](https://github.com/RhoInc/aeexplorer/wiki/Configuration) in
#' the JavaScript library.
#'
#' @examples
#' \dontrun{
#' # Render widget with defaults.
#' aeExplorer()
#'
#' # Render widget without stratification.
#' aeExplorer(
#' mapping = list(
#' dm = list(
#' id_col = 'USUBJID'
#' ),
#' aes = list(
#' id_col = 'USUBJID',
#' bodsys_col = 'AEBODSYS',
#' term_col = 'AEDECOD'
#' )
#' )
#' )
#' }
#'
#' @param data `list` Named list of data frames that includes participant-level subject data (`dm`)
#' and event-level adverse event data (`aes`).
#' @param mapping `list` Named list with current data mappings. See details for default mapping.
#' @param ... additional options to be added to mapping. Will overwrite mapping.
#'
#' @importFrom purrr list_modify
#'
#' @export

aeExplorer <- function(
data = list(
dm = safetyData::sdtm_dm,
aes = safetyData::sdtm_ae
),
mapping = NULL,
...
) {
# Default mapping - TODO: retrieve mapping from a dedicated file or object (in safetyGraphics?).
if (is.null(mapping)) {
mapping <- list(
dm = list(
id_col = 'USUBJID',
treatment_col = 'ARM'
),
aes = list(
id_col = 'USUBJID',
bodsys_col = 'AEBODSYS',
term_col = 'AEDECOD'
)
)
}

# Add ... to mapping.
if (length(list(...)) > 0) {
mapping <- purrr::list_modify(mapping, !!!list(...))
}

initialized <- init_aeExplorer(
data = data,
settings = mapping
)

# Render widget as standalone HTML page.
render_widget("aeExplorer", initialized$data, initialized$settings)
}
21 changes: 12 additions & 9 deletions R/hepExplorer.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#'
#' Convience mapping of render_widget for hepExplorer.
#'
#' @details The [data](https://github.com/SafetyGraphics/hep-explorer/wiki/Data-Guidelines) and [mapping](https://github.com/SafetyGraphics/hep-explorer/wiki/Configuration) should match the specs described in the [hepExplorer](https://github.com/SafetyGraphics/hep-explorer/wiki/Configuration) javascript library. Items passed in ... are added to mapping, and then the list is converted to json via `jsonlite::toJSON(mapping, auto_unbox=TRUE, null="null")`.
#' The [data](https://github.com/SafetyGraphics/hep-explorer/wiki/Data-Guidelines) and [mapping](https://github.com/SafetyGraphics/hep-explorer/wiki/Configuration) should match the specs described in the [hepExplorer](https://github.com/SafetyGraphics/hep-explorer/wiki/Configuration) javascript library. Items passed in ... are added to mapping, and then the list is converted to json via `jsonlite::toJSON(mapping, auto_unbox=TRUE, null="null")`.
#'
#' The default mapping shown below is designed to work with data in the CDISC ADaM format (like `safetydata::adam_adlbc`).
#'
Expand Down Expand Up @@ -48,7 +48,7 @@
#'
#' # Use custom mapping for SDTM data
#' hepExplorer(
#' df=safetyData::sdtm_lb,
#' data=safetyData::sdtm_lb,
#' measure_col = "LBTEST",
#' measure_values = list(
#' ALT = "Alanine Aminotransferase",
Expand All @@ -66,17 +66,20 @@
#' )
#' }
#'
#' @param df data frame containing lab data used to render for hepExplorer. Default is safetyData::adam_adlbc.
#' @param mapping named list with the current data mappings. See details for default mapping.
#' @param data `data.frame` Data frame containing lab data used to render `hepExplorer`. Default: `safetyData::adam_adlbc`
#' @param mapping `list` named list with the current data mappings. See details for default mapping.
#' @param ... additional options to be added to mapping. Will overwrite mapping.
#'
#' @importFrom purrr list_modify
#'
#' @export

hepExplorer <- function(df=safetyData::adam_adlbc, mapping=NULL, ...){

#default mapping
hepExplorer <- function(
data = safetyData::adam_adlbc,
mapping = NULL,
...
) {
# default mapping
if(is.null(mapping)){
mapping <- list(
measure_col = "PARAM",
Expand All @@ -102,5 +105,5 @@ hepExplorer <- function(df=safetyData::adam_adlbc, mapping=NULL, ...){
}

# render widget as standalone html page
render_widget("hepExplorer" ,df, mapping)
}
render_widget("hepExplorer" ,data, mapping)
}
42 changes: 37 additions & 5 deletions R/init_aeExplorer.R
Original file line number Diff line number Diff line change
@@ -1,17 +1,42 @@
#' Initialize Settings for Adverse Event Explorer widget
#'
#' @param data labs data structured as one record per person per visit per measurement. See details for column requirements.
#' @param settings named list of settings
#' @param data `list` Named list of data frames that includes participant-level subject data (`dm`)
#' and event-level adverse event data (`aes`).
#' @param settings `list` Named list of settings.
#'
#' @return returns list with data and settings
#'
#' @import dplyr
#'
#' @export


init_aeExplorer <- function(data, settings) {

# creates flag if treatment_col is missing to trigger actions to avoid downstream JS errors and enable visualization of blinded(no treatment_col) data
missing_trt_flag <- (
is.null(settings[["dm"]][["treatment_col"]]) || # Check NULL first and evaluate logic left to right
trimws(settings[["dm"]][["treatment_col"]])==""
)

#if no treatment_col provided, create dummy treatment_col for group setting so that ae explorer JS doesn't bomb
if (missing_trt_flag) {
data$dm <- data$dm %>% dplyr::mutate(group_placeholder="All")
settings[["dm"]][["treatment_col"]] <- "group_placeholder"
}

# Merge treatment with adverse events.
dm_sub <- data$dm %>% select(settings[["dm"]][["id_col"]], settings[["dm"]][["treatment_col"]])
anly <- dm_sub %>% left_join(data$aes) # left join to keep all rows in dm (even if there were no AEs)
dm_sub <- data$dm %>%
dplyr::select(
settings[["dm"]][["id_col"]],
settings[["dm"]][["treatment_col"]]
)

# left join to keep all rows in dm (even if there were no AEs)
anly <- dm_sub %>%
dplyr::left_join(
data$aes,
settings[['dm']][['id_col']]
)

ae_settings <- list()

Expand All @@ -37,5 +62,12 @@ init_aeExplorer <- function(data, settings) {
values = c("", NA, NULL)
)
)

#if no treatment_col provided, remove total column and group selection dropdown
if (missing_trt_flag){
ae_settings$defaults[["groupCols"]] = FALSE
ae_settings$defaults[["useVariableControls"]] = FALSE
}

return(list(data = anly, settings = ae_settings))
}
2 changes: 1 addition & 1 deletion R/init_aeTimelines.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#' Initialize Settings for AE Timeline widget
#'
#' @param data labs data structured as one record per person per visit per measurement. See details for column requirements.
#' @param data adverse events data structured as one record per event. See details for column requirements.
#' @param settings named list of settings
#'
#' @return returns list with data and settings
Expand Down
Loading

0 comments on commit fce6b3c

Please sign in to comment.