Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gsm v2.2.1 release candidate #2008

Merged
merged 3 commits into from
Jan 6, 2025
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
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: gsm
Title: Good Statistical Monitoring
Version: 2.2.0.9999
Version: 2.2.1
Authors@R: c(
person("George", "Wu", , "george.wu@gilead.com", role = c("aut", "cre")),
person("Jeremy", "Wildfire", , "jwildfire@gmail.com", role = "aut"),
Expand Down
11 changes: 11 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
# gsm v2.2.1

This patch release primarily addresses minor report updates bug fixes. Specifically:

- Reduce size of flags over time table by only displaying the most recent 12 periods
- Return an object of class `function` from `GetStrFunctionIfNamespaced()`
- Generalize all `Flag_*()` functions to a single `Flag()` function
- Use `log4r` framework set up in v2.2.0 for `stopif()`/`stopifnot()` calls
- Add Subject Disposition field to Study Completion domain


# gsm v2.2.0

This minor release prepares the gsm to be used as part of a more sophisticated pipeline, through the addition of
Expand Down
3 changes: 1 addition & 2 deletions R/Analyze_NormalApprox.R
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ Analyze_NormalApprox <- function(
dfTransformed,
strType = "binary"
) {

stop_if(cnd = !is.data.frame(dfTransformed), message ="dfTransformed is not a data.frame")
stop_if(cnd = !is.data.frame(dfTransformed), message = "dfTransformed is not a data.frame")
stop_if(
cnd = !all(c("GroupID", "GroupLevel", "Denominator", "Numerator", "Metric") %in% names(dfTransformed)),
message = "One or more of these columns not found: GroupID, GroupLevel, Denominator, Numerator, Metric"
Expand Down
29 changes: 15 additions & 14 deletions R/Flag.R
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,10 @@
Flag <- function(
dfAnalyzed,
strColumn = "Score",
vThreshold = c(-3,-2,2,3),
vFlag = c(-2,-1,0,1,2),
vFlagOrder = c(2,-2,1,-1,0)
vThreshold = c(-3, -2, 2, 3),
vFlag = c(-2, -1, 0, 1, 2),
vFlagOrder = c(2, -2, 1, -1, 0)
) {

stop_if(cnd = !is.data.frame(dfAnalyzed), message = "dfAnalyzed is not a data frame")
stop_if(cnd = !is.character(strColumn), message = "strColumn is not character")
stop_if(cnd = !is.numeric(vThreshold), message = "vThreshold is not numeric")
Expand All @@ -59,23 +58,25 @@ Flag <- function(
stop_if(cnd = length(strColumn) != 1, message = "strColumn must be length of 1")
stop_if(cnd = !(strColumn %in% names(dfAnalyzed)), message = "strColumn not found in dfAnalyzed")
stop_if(cnd = !is.numeric(vFlag), message = "vFlag must be numeric")
stop_if(cnd = length(vFlag) != length(vThreshold)+1, message = "Improper number of Flag values provided")
stop_if(cnd = length(vFlag) != length(vThreshold) + 1, message = "Improper number of Flag values provided")
stop_if(cnd = !is.numeric(vFlagOrder) & !is.null(vFlagOrder), message = "vFlagOrder must be numeric or NULL")

dfFlagged <- dfAnalyzed

# generate flag values for dfAnalyzed[strColumn] based on vThresold and vFlag
dfFlagged$Flag <- cut(
dfFlagged[[strColumn]],
breaks = c(-Inf, vThreshold, Inf),
labels = vFlag,
right = FALSE
) %>% as.character() %>% as.numeric() #Parse from factor to numeric
dfFlagged[[strColumn]],
breaks = c(-Inf, vThreshold, Inf),
labels = vFlag,
right = FALSE
) %>%
as.character() %>%
as.numeric() # Parse from factor to numeric

# Apply custom sort order using vFlagOrder
if(!is.null(vFlagOrder)){
#all values in vFlag should be included in vFlagOrder
if(identical(sort(vFlag), sort(vFlagOrder))){
if (!is.null(vFlagOrder)) {
# all values in vFlag should be included in vFlagOrder
if (identical(sort(vFlag), sort(vFlagOrder))) {
dfFlagged <- dfFlagged %>% arrange(match(.data$Flag, vFlagOrder))
LogMessage(
level = "info",
Expand All @@ -87,7 +88,7 @@ Flag <- function(
level = "info",
message = "Mismatch in vFlagOrder and vFlag values. Aborting Sort and returning unsorted data.",
cli_detail = "alert_info"
)
)
}
}

Expand Down
1 change: 0 additions & 1 deletion R/Report_FormatFlag.R
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,3 @@ Report_FormatFlag <- function(flag_value, title = NULL) {
fa_titled <- function(name, fill, title) {
fontawesome::fa(name, fill = fill, title = title)
}

8 changes: 5 additions & 3 deletions R/Summarize.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#' when associated with a workflow.
#'
#' @examples
#'
#'
#' dfTransformed <- Transform_Rate(analyticsInput)
#' dfAnalyzed <- Analyze_NormalApprox(dfTransformed)
#' dfFlagged <- Flag(dfAnalyzed)
Expand All @@ -37,8 +37,10 @@ Summarize <- function(
nMinDenominator = NULL
) {
stop_if(cnd = !is.data.frame(dfFlagged), message = "dfFlagged is not a data frame")
stop_if(cnd = !all(c("GroupID", "GroupLevel", "Flag", "Score") %in% names(dfFlagged)),
message = "One or more of these columns: GroupID, GroupLevel, Flag, Score, not found in dfFlagged" )
stop_if(
cnd = !all(c("GroupID", "GroupLevel", "Flag", "Score") %in% names(dfFlagged)),
message = "One or more of these columns: GroupID, GroupLevel, Flag, Score, not found in dfFlagged"
)

if (!("Numerator" %in% colnames(dfFlagged))) {
dfFlagged$Numerator <- NA
Expand Down
6 changes: 3 additions & 3 deletions R/Visualize_Score.R
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ Visualize_Score <- function(
bFlagFilter = FALSE,
strTitle = ""
) {
stop_if(cnd = !is.character(strTitle), message = "strTitle must be character" )
stop_if(cnd = !is.character(strTitle), message = "strTitle must be character")
stop_if(cnd = !is.logical(bFlagFilter), message = "bFlagFilter must be logical")
stop_if(cnd = !is.data.frame(dfResults), message = "dfResults must be a data.frame")
stop_if(cnd = !(length(strType) == 1), message = "strType must be length 1" )
stop_if(cnd = !(strType %in% c("Metric", "Score")), message = "strType must be 'Metric' or 'Score'" )
stop_if(cnd = !(length(strType) == 1), message = "strType must be length 1")
stop_if(cnd = !(strType %in% c("Metric", "Score")), message = "strType must be 'Metric' or 'Score'")

dfResults$FlagAbs <- abs(dfResults$Flag)
flagBreaks <- as.character(unique(sort(dfResults$FlagAbs)))
Expand Down
2 changes: 1 addition & 1 deletion R/Widget_FlagOverTime.R
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ Widget_FlagOverTime <- function(
bDebug = FALSE
) {
stop_if(cnd = !is.data.frame(dfResults), message = "dfResults is not a data.frame")
stop_if(cnd = !is.data.frame(dfMetrics),"dfMetrics is not a data.frame")
stop_if(cnd = !is.data.frame(dfMetrics), "dfMetrics is not a data.frame")
stop_if(cnd = !is.character(strGroupLevel), "strGroupLevel is not a character")
stop_if(cnd = !is.character(strFootnote) && !is.null(strFootnote), "strFootnote is not a character or NULL")
stop_if(cnd = !is.logical(bDebug), "bDebug is not a logical")
Expand Down
8 changes: 4 additions & 4 deletions R/Widget_GroupOverview.R
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ Widget_GroupOverview <- function(
strGroupLabelKey = "InvestigatorLastName",
bDebug = FALSE
) {
stop_if(cnd = !is.data.frame(dfResults),"dfResults is not a data.frame")
stop_if(cnd = !is.data.frame(dfMetrics),"dfMetrics is not a data.frame")
stop_if(cnd = !is.data.frame(dfGroups),"dfGroups is not a data.frame")
stop_if(cnd = !is.character(strGroupSubset),"strGroupSubset is not a character")
stop_if(cnd = !is.data.frame(dfResults), "dfResults is not a data.frame")
stop_if(cnd = !is.data.frame(dfMetrics), "dfMetrics is not a data.frame")
stop_if(cnd = !is.data.frame(dfGroups), "dfGroups is not a data.frame")
stop_if(cnd = !is.character(strGroupSubset), "strGroupSubset is not a character")
stop_if(cnd = !is.character(strGroupLabelKey) && !is.null(strGroupLabelKey), "strGroupLabelKey is not a character or NULL")
stop_if(cnd = !is.logical(bDebug), "bDebug is not a logical")

Expand Down
10 changes: 5 additions & 5 deletions R/Widget_ScatterPlot.R
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ Widget_ScatterPlot <- function(
strShinyGroupSelectID = "GroupID",
bDebug = FALSE
) {
stop_if(cnd = !is.data.frame(dfResults),"dfResults is not a data.frame")
stop_if(cnd = !is.data.frame(dfResults), "dfResults is not a data.frame")
stop_if(cnd = !(is.null(lMetric) || (is.list(lMetric) && !is.data.frame(lMetric))), "lMetric must be a list, but not a data.frame")
stop_if(cnd = !(is.null(dfGroups) || is.data.frame(dfGroups)),"dfGroups is not a data.frame")
stop_if(cnd = !(is.null(dfBounds) || is.data.frame(dfBounds)),"dfBounds is not a data.frame")
stop_if(cnd = !is.logical(bAddGroupSelect),"bAddGroupSelect is not a logical")
stop_if(cnd = !is.character(strShinyGroupSelectID),"strShinyGroupSelectID is not a character")
stop_if(cnd = !(is.null(dfGroups) || is.data.frame(dfGroups)), "dfGroups is not a data.frame")
stop_if(cnd = !(is.null(dfBounds) || is.data.frame(dfBounds)), "dfBounds is not a data.frame")
stop_if(cnd = !is.logical(bAddGroupSelect), "bAddGroupSelect is not a logical")
stop_if(cnd = !is.character(strShinyGroupSelectID), "strShinyGroupSelectID is not a character")
stop_if(cnd = !is.logical(bDebug), "bDebug is not a logical")

# define widget inputs
Expand Down
15 changes: 7 additions & 8 deletions R/Widget_TimeSeries.R
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,14 @@ Widget_TimeSeries <- function(
strShinyGroupSelectID = "GroupID",
bDebug = FALSE
) {

stop_if(cnd = !is.data.frame(dfResults),"dfResults is not a data.frame")
stop_if(cnd = !is.data.frame(dfResults), "dfResults is not a data.frame")
stop_if(cnd = !(is.null(lMetric) || (is.list(lMetric) && !is.data.frame(lMetric))), "lMetric must be a list, but not a data.frame")
stop_if(cnd = !(is.null(dfGroups) || is.data.frame(dfGroups)),"dfGroups is not a data.frame")
stop_if(cnd = length(strOutcome) != 1,"strOutcome must be length 1")
stop_if(cnd = !is.character(strOutcome),"strOutcome is not a character")
stop_if(cnd = !is.logical(bAddGroupSelect),"bAddGroupSelect is not a logical")
stop_if(cnd = !is.character(strShinyGroupSelectID),"strShinyGroupSelectID is not a character")
stop_if(cnd = !is.logical(bDebug), "bDebug is not a logical" )
stop_if(cnd = !(is.null(dfGroups) || is.data.frame(dfGroups)), "dfGroups is not a data.frame")
stop_if(cnd = length(strOutcome) != 1, "strOutcome must be length 1")
stop_if(cnd = !is.character(strOutcome), "strOutcome is not a character")
stop_if(cnd = !is.logical(bAddGroupSelect), "bAddGroupSelect is not a logical")
stop_if(cnd = !is.character(strShinyGroupSelectID), "strShinyGroupSelectID is not a character")
stop_if(cnd = !is.logical(bDebug), "bDebug is not a logical")

# Parse `vThreshold` from comma-delimited character string to numeric vector.
if (!is.null(vThreshold)) {
Expand Down
2 changes: 1 addition & 1 deletion R/util-CalculatePercentage.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#' @description
#'
#' Used to create percentage values on enrollment data, such as site activation and
#' and participantment enrollment, and pasting together an appropriate n/N (xx.x%) value
#' and participant enrollment, and pasting together an appropriate n/N (xx.x%) value
#' as well.
#'
#' @param data The input dataframe
Expand Down
2 changes: 1 addition & 1 deletion R/util-Ingest.R
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
#' @export

Ingest <- function(lSourceData, lSpec, strDomain = "Raw") {
stop_if(!is.list(lSourceData),"[ lSourceData ] must be a list.")
stop_if(!is.list(lSourceData), "[ lSourceData ] must be a list.")
stop_if(!is.list(lSpec), "[ lSpec ] must be a list.")

# If there is a domain (specificed with and underscore) in lSourceData/lSpec names, remove it
Expand Down
2 changes: 1 addition & 1 deletion R/util-MakeBounds.R
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ MakeBounds <- function(
vThreshold <- ParseThreshold(strThreshold = lMetric$Threshold)
if (!is.null(lMetric$AnalysisType) &&
tolower(unique(lMetric$AnalysisType)) %in% c("identity")) {
dfBounds <- NULL
dfBounds <- NULL
} else if (!is.null(lMetric$AnalysisType) &&
tolower(unique(lMetric$AnalysisType)) %in% c("poisson")) {
dfBounds <- Analyze_Poisson_PredictBounds(
Expand Down
2 changes: 1 addition & 1 deletion R/util-MakeWorkflowList.R
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ MakeWorkflowList <- function(
if (length(strPackage)) {
path <- system.file(strPath, package = strPackage)
}
stop_if(!dir.exists(path), "[ strPath ] must exist." )
stop_if(!dir.exists(path), "[ strPath ] must exist.")
path <- tools::file_path_as_absolute(path)

# list all files to loop through to build the workflow list.
Expand Down
30 changes: 15 additions & 15 deletions R/util-Report.R
Original file line number Diff line number Diff line change
Expand Up @@ -64,33 +64,33 @@ FilterByLatestSnapshotDate <- function(df, strSnapshotDate = NULL) {
#' @export

FilterByFlags <- function(
dfResults,
bCurrentlyFlagged = FALSE
dfResults,
bCurrentlyFlagged = FALSE
) {
dfResultsFlagged <- dfResults %>%
group_by(.data$GroupID, .data$MetricID) %>%
mutate(
flagsum = sum(abs(.data$Flag), na.rm = TRUE),
flaglatest = Flag[SnapshotDate == max(SnapshotDate)]
flagsum = sum(abs(.data$Flag), na.rm = TRUE),
flaglatest = Flag[SnapshotDate == max(SnapshotDate)]
) %>%
ungroup() %>%
filter(
.data$flagsum > 0
)

if (bCurrentlyFlagged) {
dfResultsFlagged <- dfResultsFlagged %>%
filter(
.data$flaglatest != 0
)
}

if (bCurrentlyFlagged) {
dfResultsFlagged <- dfResultsFlagged %>%
select(-all_of(c(
'flagsum', 'flaglatest'
)))
filter(
.data$flaglatest != 0
)
}

dfResultsFlagged <- dfResultsFlagged %>%
select(-all_of(c(
"flagsum", "flaglatest"
)))

return(dfResultsFlagged)
return(dfResultsFlagged)
}

add_Groups_metadata <- function(
Expand Down
2 changes: 1 addition & 1 deletion man/CalculatePercentage.Rd

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

Loading
Loading