Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
de16095
toggle state of field level selections
Feb 15, 2019
4bbfc4b
rearrange rows, add setting_cat column
Feb 20, 2019
1aa07a3
create functions for making the UI
Feb 20, 2019
3b7c1fa
switch to automated UI!
Feb 20, 2019
2f281f9
switch to automated UI generation/population
Feb 20, 2019
5d7c82f
little fixes in server.R
Feb 20, 2019
2605626
delete old manual UI code
Feb 20, 2019
6ad72d1
add chart selection
Feb 21, 2019
9841dbf
toggle field-level inputs on and off
Feb 21, 2019
b6dc752
add some notes to self
Feb 21, 2019
535667a
add more notes to self re: modules
Feb 21, 2019
049d36d
dynamically update field-level inputs
Feb 21, 2019
ca4561a
update version
jwildfire Feb 22, 2019
81e7390
update data standard tracking
jwildfire Feb 22, 2019
b2d8199
automate standard adjudication
jwildfire Feb 22, 2019
bfa4aec
a few more tests. change standard order.
jwildfire Feb 22, 2019
da43487
update docs
jwildfire Feb 22, 2019
0e40f46
clear checks
jwildfire Feb 22, 2019
1a54ee8
update comment for field-level stuff
Feb 22, 2019
4e6537d
Merge pull request #191 from ASA-DIA-InteractiveSafetyGraphics/dev-v0…
Feb 22, 2019
700bc35
change input name
Feb 22, 2019
ed44334
separate functions into files
Feb 22, 2019
cb6b41f
add comments
Feb 22, 2019
0ac3bee
clarify comment
Feb 25, 2019
bceb364
removing some old comments..
Feb 25, 2019
afd37b2
add setting_cat
Feb 25, 2019
b1f5a4b
add setting_cat
Feb 25, 2019
20ada87
merge in ui updates
jwildfire Feb 25, 2019
0df1f6e
fix test
jwildfire Feb 25, 2019
f6a77a1
sync data module with standard refactor
jwildfire Feb 25, 2019
e33a16f
Merge pull request #194 from ASA-DIA-InteractiveSafetyGraphics/modula…
Feb 25, 2019
6711937
clear check
jwildfire Feb 25, 2019
31a211f
Merge branch 'dev-v0.9.0' into refactor-standards
jwildfire Feb 25, 2019
594ba4d
Merge pull request #190 from ASA-DIA-InteractiveSafetyGraphics/refact…
Feb 25, 2019
ef4a00c
start settings page refactor
jwildfire Feb 25, 2019
097386c
document shiny app functions
Feb 26, 2019
07e1d57
Merge pull request #195 from ASA-DIA-InteractiveSafetyGraphics/shiny_…
Feb 26, 2019
684050a
more UI tweaks
jwildfire Feb 26, 2019
2b4f7a1
Merge branch 'dev-v0.9.0' into css-tweaks
jwildfire Feb 26, 2019
7774941
add function for section render
jwildfire Feb 26, 2019
63865f6
more refactor
jwildfire Feb 26, 2019
375cba3
import haven::read_sas
Feb 27, 2019
8f3bd28
Merge pull request #197 from ASA-DIA-InteractiveSafetyGraphics/add_haven
Feb 27, 2019
009de03
update validation styles
jwildfire Feb 27, 2019
e62e9bc
Merge pull request #196 from ASA-DIA-InteractiveSafetyGraphics/css-tw…
Feb 28, 2019
e53dad9
tweak size option. fix #203
jwildfire Feb 28, 2019
26ee995
update docs
jwildfire Feb 28, 2019
15fc0d1
Merge pull request #204 from ASA-DIA-InteractiveSafetyGraphics/tweak-…
Feb 28, 2019
e39bc2e
import shinywidgets::materialSwitch()
Feb 28, 2019
8f273ec
import shinyWidgets
Mar 1, 2019
6fa5f87
Merge pull request #205 from ASA-DIA-InteractiveSafetyGraphics/app-li…
Mar 4, 2019
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
6 changes: 4 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: safetyGraphics
Title: Create Interactive Graphics Related to Clinical Trial Safety
Version: 0.8.1
Version: 0.9.0
Authors@R: c(
person("Jeremy", "Wildfire", email = "jeremy_wildfire@rhoworld.com", role = c("cre","aut")),
person("Becca", "Krouse", role="aut"),
Expand Down Expand Up @@ -35,5 +35,7 @@ Imports:
rmarkdown,
rlang,
tibble,
utils
utils,
haven,
shinyWidgets
VignetteBuilder: knitr
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import(rmarkdown)
import(shinyjs)
importFrom(dplyr,"filter")
importFrom(dplyr,filter)
importFrom(haven,read_sas)
importFrom(magrittr,"%>%")
importFrom(purrr,keep)
importFrom(purrr,map)
Expand All @@ -25,6 +26,7 @@ importFrom(purrr,map_lgl)
importFrom(rlang,.data)
importFrom(rlang,parse_expr)
importFrom(shiny,runApp)
importFrom(shinyWidgets,materialSwitch)
importFrom(stringr,str_detect)
importFrom(stringr,str_split)
importFrom(stringr,str_subset)
Expand Down
61 changes: 39 additions & 22 deletions R/detectStandard.R
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
#' Detect the data standard used for a data set
#'
#' This function attempts to detect the data CDISC clinical standard used in a given R data frame.
#' This function attempts to detect the clinical data standard used in a given R data frame.
#'
#' This function compares the columns in the provided \code{"data"} with the required columns for a given data standard/domain combination. The function is designed to work with the SDTM and AdAM CDISC(<https://www.cdisc.org/>) standards for clinical trial data. Currently, "labs" is the only domain supported.
#' This function compares the columns in the provided \code{"data"} with the required columns for a given data standard/domain combination. The function is designed to work with the SDTM and AdAM CDISC(<https://www.cdisc.org/>) standards for clinical trial data by default. Additional standards can be added by modifying the \code{"standardMetadata"} data set included as part of this package. Currently, "labs" is the only domain supported.
#'
#' @param data A data frame in which to detect the data standard
#' @param includeFields specifies whether to check the data set for field level data in addition to columns. Default: \code{TRUE}.
#' @param domain The data domain for the data set provided. Default: \code{"labs"}.
#' @return A list containing the matching \code{"standard"} ("ADaM", "SDTM" or "None") and a list of \code{"details"} describing each standard considered.
#' @return A list containing the matching \code{"standard"} from \code{"standardMetadata"} and a list of \code{"details"} describing each standard considered.
#' @examples

#' detectStandard(adlbc)[["standard"]] #AdAM
#' detectStandard(adlbc)[["standard"]] #adam
#' detectStandard(iris)[["standard"]] #none
#'
#' \dontrun{
Expand All @@ -26,28 +26,45 @@ detectStandard <- function(data, includeFields=TRUE, domain="labs"){
)


# Create placeholder list, with Standard = None.
# Create placeholder list, with Standard = none.
available_standards <- safetyGraphics::standardsMetadata %>% select(-.data$text_key) %>% names
standard_list <- list()
standard_list[["details"]] = list()
standard_list[["details"]][["ADaM"]]<-evaluateStandard(data,standard="ADaM", includeFields=includeFields, domain=domain)
standard_list[["details"]][["SDTM"]]<-evaluateStandard(data,standard="SDTM", includeFields=includeFields, domain=domain)
standard_list[["standard"]] = "none"
standard_list[["standard_percent"]] = 0

for(standard in available_standards){
# evaluate the current standard and save the result
standard_list[["details"]][[standard]]<-evaluateStandard(data,standard=standard, includeFields=includeFields, domain=domain)

# if the current standard is a better match, use it as the overall standard
# if there is a tie, don't change the standard - this means the column order in standardMetadata breaks ties!
current_percent <- standard_list[["details"]][[standard]][["match_percent"]]
overall_percent <- standard_list[["standard_percent"]]
if(current_percent > overall_percent){
standard_list[["standard"]] <- standard
standard_list[["standard_percent"]] <- current_percent
}
}

# Determine the final standard
if(standard_list[["details"]][["SDTM"]][["match"]] == "Full"){
standard_list[["standard"]]<- "SDTM"
} else if(standard_list[["details"]][["ADaM"]][["match"]] == "Full"){
standard_list[["standard"]]<- "ADaM"
} else if(standard_list[["details"]][["SDTM"]][["match"]] == "Partial" |
standard_list[["details"]][["ADaM"]][["match"]] == "Partial"){
standard_list[["standard"]] <- ifelse(
length(standard_list[["details"]][["ADaM"]][["valid_count"]]) >
length(standard_list[["details"]][["SDTM"]][["valid_count"]]),
"ADaM" , "SDTM" #SDTM if they are equal
)

} else {
standard_list[["standard"]]<-"None"
}

# TODO: write a general algorithm to do this ...
# if(standard_list[["details"]][["sdtm"]][["match"]] == "Full"){
# standard_list[["standard"]]<- "sdtm"
# } else if(standard_list[["details"]][["adam"]][["match"]] == "Full"){
# standard_list[["standard"]]<- "adam"
# } else if(standard_list[["details"]][["sdtm"]][["match"]] == "Partial" |
# standard_list[["details"]][["adam"]][["match"]] == "Partial"){
# standard_list[["standard"]] <- ifelse(
# length(standard_list[["details"]][["adam"]][["valid_count"]]) >
# length(standard_list[["details"]][["sdtm"]][["valid_count"]]),
# "adam" , "sdtm" #SDTM if they are equal
# )
#
# } else {
# standard_list[["standard"]]<-"None"
# }

return(standard_list)
}
22 changes: 11 additions & 11 deletions R/evaluateStandard.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#' @param includeFields should field level data be evaluated?
#' @param domain data domain. "labs" only for now.
#'
#' @return a list describing to what degree the data set matches the data standard. The "match" property describes compliance with the standard as "Full", "Partial" or "None". The "checks" property is a list of the data elements expected for the standard and whether they are "valid" in the given data set. "valid_checks" and "invalid_checks" provide counts of the specified checks.
#' @return a list describing to what degree the data set matches the data standard. The "match" property describes compliance with the standard as "full", "partial" or "none". The "checks" property is a list of the data elements expected for the standard and whether they are "valid" in the given data set. "total_checks", "valid_checks" and "invalid_checks" provide counts of the specified checks. "match_percent" is calculated as valid_checks/total_checks.
#'
#' @examples
#' safetyGraphics:::evaluateStandard(data=adlbc, standard="adam") # Match is TRUE
Expand All @@ -26,8 +26,7 @@ evaluateStandard <- function(data, standard, includeFields=TRUE, domain="labs"){
is.data.frame(data),
is.character(standard),
is.logical(includeFields),
is.character(domain),
tolower(standard) %in% c("adam","sdtm")
is.character(domain)
)

standard<-tolower(standard)
Expand All @@ -43,7 +42,8 @@ evaluateStandard <- function(data, standard, includeFields=TRUE, domain="labs"){
mutate(type = ifelse(.data$column_mapping, "column", "field")) %>%
rowwise %>%
mutate(field_column_name = ifelse(.data$field_mapping, getSettingsMetadata(cols=standard, text_keys=.data$field_column_key),"")) %>%
mutate(valid = ifelse(.data$column_mapping,
mutate(
valid = ifelse(.data$column_mapping,
hasColumn(data=data, columnName=.data$standard_val),
hasField(data=data, columnName=.data$field_column_name, fieldValue=.data$standard_val)
)) %>%
Expand All @@ -54,20 +54,20 @@ evaluateStandard <- function(data, standard, includeFields=TRUE, domain="labs"){
standardChecks <- standardChecks %>% filter(.data$type != "field")
}

# compare_summary[["checks"]] <- split(standardChecks, seq(nrow(standardChecks)))%>%map(~as.list(.)) #coerce to list of lists?
compare_summary[["checks"]] <- standardChecks #or just keep the tibble ...
compare_summary[["checks"]] <- standardChecks

# count valid/invalid data elements
compare_summary[["total_count"]] <- standardChecks %>% nrow()
compare_summary[["valid_count"]] <- standardChecks %>% filter(.data$valid) %>% nrow()
compare_summary[["invalid_count"]] <- standardChecks %>% filter(!.data$valid) %>% nrow()


compare_summary[["match_percent"]] <- compare_summary[["valid_count"]] / compare_summary[["total_count"]]
if (compare_summary[["invalid_count"]]==0) {
compare_summary[["match"]] <- "Full"
compare_summary[["match"]] <- "full"
} else if(compare_summary[["valid_count"]]>0) {
compare_summary[["match"]] <- "Partial"
compare_summary[["match"]] <- "partial"
} else {
compare_summary[["match"]] <- "None"
compare_summary[["match"]] <- "none"
}

return(compare_summary)
Expand Down
11 changes: 9 additions & 2 deletions R/getSettingsMetadata.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#' @param charts optional vector of chart names used to filter the metadata. Exact matches only (case-insensitive). All rows returned by default.
#' @param text_keys optional vector of keys used to filter the metadata. Partial matches for any of the strings are returned (case-insensitive). All rows returned by default.
#' @param filter_expr optional filter expression used to subset the data.
#' @param add_standards should data standard info stored in standardsMetadata be included
#' @param cols optional vector of columns to return from the metadata. All columns returned by default.
#' @param metadata metadata data frame to be queried
#'
Expand All @@ -27,9 +28,15 @@
#'
#' @export

getSettingsMetadata<-function(charts=NULL, text_keys=NULL, cols=NULL, filter_expr=NULL, metadata = safetyGraphics::settingsMetadata){
getSettingsMetadata<-function(charts=NULL, text_keys=NULL, cols=NULL, filter_expr=NULL, add_standards=TRUE, metadata = safetyGraphics::settingsMetadata){

md <- metadata
md <- metadata %>% mutate(text_key=as.character(.data$text_key))

if(add_standards){
ms<-safetyGraphics::standardsMetadata %>% mutate(text_key=as.character(.data$text_key))
md<-md%>%left_join(ms, by="text_key")
}

all_columns <- names(md)

#filter the metadata based on the charts option (if any)
Expand Down
8 changes: 6 additions & 2 deletions R/safetyGraphicsApp.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,16 @@
#' @importFrom purrr map keep
#' @importFrom magrittr "%>%"
#' @import rmarkdown
#' @importFrom haven read_sas
#' @importFrom shinyWidgets materialSwitch
#'
#' @export
#'
safetyGraphicsApp <- function(maxFileSize = 20) {
safetyGraphicsApp <- function(maxFileSize = NULL) {
#increase maximum file upload limit
options(shiny.maxRequestSize=(maxFileSize*1024^2))
if(!is.null(maxFileSize)){
options(shiny.maxRequestSize=(maxFileSize*1024^2))
}

path <- system.file("eDISH_app", package = "safetyGraphics")
shiny::runApp(path, launch.browser = TRUE)
Expand Down
3 changes: 1 addition & 2 deletions R/settingsMetadata.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
#' \item{column_type}{Expected type for the data column values. Should be "character","logical" or "numeric"}
#' \item{field_mapping}{Flag indicating whether the setting corresponds to a field-level mapping in the data}
#' \item{field_column_key}{Key for the column that provides options for the field-level mapping in the data}
#' \item{adam}{Settings values for the ADaM standard}
#' \item{sdtm}{Settings values for the SDTM standard}
#' \item{setting_cat}{Setting category (data, measure, appearance)}
#' }
#'
#' @source Created for this package
Expand Down
13 changes: 13 additions & 0 deletions R/standardsMetadata.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#' Standards Metadata
#'
#' Metadata about the data standards used to configure safetyGraphics charts. One record per unique setting. Columns contain default setting values for clinical data standards, like the CDISC "adam" and "sdtm" standards.
#'
#' @format A data frame with 25 rows and 3 columns
#' \describe{
#' \item{text_key}{Text key indicating the setting name. \code{'--'} delimiter indicates a nested setting}
#' \item{adam}{Settings values for the ADaM standard}
#' \item{sdtm}{Settings values for the SDTM standard}
#' }
#'
#' @source Created for this package
"standardsMetadata"
5 changes: 4 additions & 1 deletion data-raw/csv_to_rda.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,8 @@ library(usethis)
ablbc <- read.csv("data-raw/adlbc.csv")
usethis::use_data(adlbc, overwrite = TRUE)

settingsMetadata<- read.csv("data-raw/settingsMetadata.csv")
settingsMetadata <- read.csv("data-raw/settingsMetadata.csv")
usethis::use_data(settingsMetadata, overwrite = TRUE)

standardsMetadata <- read.csv("data-raw/standardsMetadata.csv")
usethis::use_data(standardsMetadata, overwrite = TRUE)
Loading