From 41117529b000796a24f0181b29fb809ea6232005 Mon Sep 17 00:00:00 2001 From: pchelle Date: Fri, 6 Sep 2024 08:59:09 -0400 Subject: [PATCH 1/3] Fixes #1274 Prevent crash of 0 simulated values in log scale Provides a warning for such a case --- R/messages.R | 7 +++++++ R/qualification-comparison-time-profile.R | 9 ++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/R/messages.R b/R/messages.R index ae259216..d85bf693 100644 --- a/R/messages.R +++ b/R/messages.R @@ -296,6 +296,13 @@ messages <- list( paste0(highlight(unique(values)), collapse = "', '"), "'." ) }, + warningLogScaleIssue = function(output) { + paste0( + "Plot scale is logarithmic, however all values from simulated output '", + highlight(output), "' were 0." + ) + }, + #----- Info messages ---- runStarting = function(runName, subRun = NULL) { if (is.null(subRun)) { diff --git a/R/qualification-comparison-time-profile.R b/R/qualification-comparison-time-profile.R index f2b62196..dde3edd4 100644 --- a/R/qualification-comparison-time-profile.R +++ b/R/qualification-comparison-time-profile.R @@ -124,7 +124,14 @@ addOutputToComparisonTimeProfile <- function(outputMapping, simulationDuration, molWeight = molWeight ) simulatedValues <- simulatedValues[selectedTimeValues] - + logScaleIssue <- all(simulatedValues == 0, isIncluded(axesProperties$y$scale, "log")) + if(logScaleIssue){ + warning(messages$warningLogScaleIssue(outputMapping$Output), call. = FALSE) + # Set the first value to 1 to avoid log scale issue + # Since this only affect one value, no line will plotted + simulatedValues[1] <- 1 + } + # Add simulated values to plot plotObject <- tlf::addLine( x = simulatedTime, From 180cd68a754db23b22786215346b938e60b65a23 Mon Sep 17 00:00:00 2001 From: pchelle Date: Fri, 6 Sep 2024 10:14:40 -0400 Subject: [PATCH 2/3] Remove the curve and legend if values are all <=0 --- R/qualification-comparison-time-profile.R | 31 ++++++++++++----------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/R/qualification-comparison-time-profile.R b/R/qualification-comparison-time-profile.R index dde3edd4..d2daaebe 100644 --- a/R/qualification-comparison-time-profile.R +++ b/R/qualification-comparison-time-profile.R @@ -124,25 +124,26 @@ addOutputToComparisonTimeProfile <- function(outputMapping, simulationDuration, molWeight = molWeight ) simulatedValues <- simulatedValues[selectedTimeValues] - logScaleIssue <- all(simulatedValues == 0, isIncluded(axesProperties$y$scale, "log")) + # If issues with log scale due to all zeros or negative values + # Warn and do not plot the data + logScaleIssue <- all(simulatedValues <= 0, isIncluded(axesProperties$y$scale, "log")) if(logScaleIssue){ warning(messages$warningLogScaleIssue(outputMapping$Output), call. = FALSE) - # Set the first value to 1 to avoid log scale issue - # Since this only affect one value, no line will plotted - simulatedValues[1] <- 1 } - # Add simulated values to plot - plotObject <- tlf::addLine( - x = simulatedTime, - y = simulatedValues, - caption = prettyCaption(paste(outputMapping$Caption, "Simulated Data"), plotObject), - linetype = tlfLinetype(outputMapping$LineStyle), - color = outputMapping$Color, - size = outputMapping$Size, - plotObject = plotObject - ) - + if(!logScaleIssue){ + # Add simulated values to plot + plotObject <- tlf::addLine( + x = simulatedTime, + y = simulatedValues, + caption = prettyCaption(paste(outputMapping$Caption, "Simulated Data"), plotObject), + linetype = tlfLinetype(outputMapping$LineStyle), + color = outputMapping$Color, + size = outputMapping$Size, + plotObject = plotObject + ) + } + # Loop on each observed dataset in OutputMappings for (observedDataSet in outputMapping$ObservedData) { # Get data and meta data of observed results From 5a12cf9397fc635d164200217abd03cefe1bd51b Mon Sep 17 00:00:00 2001 From: pchelle Date: Fri, 6 Sep 2024 10:16:01 -0400 Subject: [PATCH 3/3] Update message for <=0 --- R/messages.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/messages.R b/R/messages.R index d85bf693..a77128de 100644 --- a/R/messages.R +++ b/R/messages.R @@ -299,7 +299,7 @@ messages <- list( warningLogScaleIssue = function(output) { paste0( "Plot scale is logarithmic, however all values from simulated output '", - highlight(output), "' were 0." + highlight(output), "' were lower or equal to 0." ) },