From ed3eb41df5aa0fd2148584bd29a1dddc932b0498 Mon Sep 17 00:00:00 2001 From: Pierre Chelle <45343665+pchelle@users.noreply.github.com> Date: Fri, 26 Apr 2024 21:03:42 +0200 Subject: [PATCH] Fixes #1213 provide default axes settings in qualification workflows (#1216) --- R/qualification-time-profile.R | 19 --- R/utilities-configuration-plan.R | 31 ++++- R/utilities-task.R | 37 ++++-- inst/extdata/qualification-axis-settings.json | 114 ++++++++++++++++++ man/formatAxisProperties.Rd | 18 +++ man/getAxesPropertiesFromName.Rd | 22 ++++ man/getDefaultTimeProfileAxesSettings.Rd | 16 --- 7 files changed, 214 insertions(+), 43 deletions(-) create mode 100644 inst/extdata/qualification-axis-settings.json create mode 100644 man/formatAxisProperties.Rd create mode 100644 man/getAxesPropertiesFromName.Rd delete mode 100644 man/getDefaultTimeProfileAxesSettings.Rd diff --git a/R/qualification-time-profile.R b/R/qualification-time-profile.R index 46f83fbe1..4639713c3 100644 --- a/R/qualification-time-profile.R +++ b/R/qualification-time-profile.R @@ -586,25 +586,6 @@ getTimeProfileObservedDataFromResults <- function(observedResults, molWeight, ax )) } -#' @title getDefaultTimeProfileAxesSettings -#' @description Get the default axes settings for mean and population time profiles -#' for keeping compatibility with configuration plan from Matlab version -#' @return List of `x` and `y` axes settings -#' @keywords internal -getDefaultTimeProfileAxesSettings <- function() { - xAxis <- list( - dimension = ospsuite::ospDimensions$Time, unit = ospsuite::ospUnits$Time$h, - min = NULL, max = NULL, scale = tlf::Scaling$lin, - grid = list(color = reEnv$theme$background$xGrid$color, linetype = reEnv$theme$background$xGrid$linetype) - ) - yAxis <- list( - dimension = ospsuite::ospDimensions$`Concentration (mass)`, unit = ospsuite::ospUnits$`Concentration [mass]`$`µg/l`, - min = NULL, max = NULL, scale = tlf::Scaling$log, - grid = list(color = reEnv$theme$background$yGrid$color, linetype = reEnv$theme$background$yGrid$linetype) - ) - return(list(x = xAxis, y = yAxis)) -} - #' @title getObservedErrorValues #' @description #' Get the observed data error range to display on time profile plots diff --git a/R/utilities-configuration-plan.R b/R/utilities-configuration-plan.R index 574f8d7e3..5ffa77eab 100644 --- a/R/utilities-configuration-plan.R +++ b/R/utilities-configuration-plan.R @@ -122,6 +122,12 @@ getAxesProperties <- function(axesSettings) { return(list(x = xAxis, y = yAxis, y2 = y2Axis, y3 = y3Axis)) } +#' @title formatAxisProperties +#' @description +#' Format configuration plan field values to a list compatible with `tlf` package nomenclature +#' @param axisField List of configuration plan field properties +#' @return A list of properties compatible with `tlf` package nomenclature +#' @keywords internal formatAxisProperties <- function(axisField) { list( dimension = axisField$Dimension, @@ -137,6 +143,29 @@ formatAxisProperties <- function(axisField) { ) } +#' @title getAxesPropertiesFromName +#' @description +#' Get axes properties from global field `AxesSettings` of configuration plan if defined, +#' otherwise use default values. +#' @param configurationPlan A `ConfigurationPlan` object +#' @param plotName Field name of the plot in the configuration plan `AxesSettings` +#' @return A list of properties for axes identified for `x`, `y` and `y2` axes. +#' The identified properties are directly compatible with `tlf` package nomenclature +#' @keywords internal +#' @import jsonlite +getAxesPropertiesFromName <- function(configurationPlan, plotName) { + axesProperties <- getAxesProperties(configurationPlan$plots$AxesSettings[[plotName]]) + if (!isEmpty(axesProperties)) { + return(axesProperties) + } + # If no axes settings are defined, use default values stored in the package json file + defaultAxisSettings <- jsonlite::fromJSON( + txt = system.file("extdata", "qualification-axis-settings.json", package = "ospsuite.reportingengine"), + simplifyVector = FALSE + ) + return(getAxesProperties(defaultAxisSettings[[plotName]])) +} + #' @title updatePlotAxes #' @description Update the axes, grid and legend properties of a plot object based on the identified axes properties #' @param plotObject A ggplot object @@ -191,7 +220,7 @@ updatePlotAxes <- function(plotObject, axesProperties) { tlfLinetype <- function(configurationLinetype) { # Unknown or NULL value will translate as NULL # which will lead to use default behaviour - if (isOfLength(configurationLinetype, 0)) { + if (isEmpty(configurationLinetype)) { return() } # tolower is used to ensure that there is no issue with caps from field values diff --git a/R/utilities-task.R b/R/utilities-task.R index 358ee664d..a79874418 100644 --- a/R/utilities-task.R +++ b/R/utilities-task.R @@ -919,7 +919,10 @@ loadQualificationTimeProfilesTask <- function(workflow, configurationPlan) { workflowFolder = workflow$workflowFolder, active = active, message = defaultWorkflowMessages$plotTimeProfiles, - settings = list(axes = getAxesProperties(configurationPlan$plots$AxesSettings$TimeProfile) %||% getDefaultTimeProfileAxesSettings()) + settings = list(axes = getAxesPropertiesFromName( + configurationPlan = configurationPlan, + plotName = "TimeProfile" + )) )) } @@ -960,8 +963,14 @@ loadGOFMergedTask <- function(workflow, configurationPlan) { active = active, message = defaultWorkflowMessages$plotGOFMerged, settings = list( - predictedVsObserved = list(axes = getAxesProperties(configurationPlan$plots$AxesSettings$GOFMergedPlotsPredictedVsObserved)), - residualsOverTime = list(axes = getAxesProperties(configurationPlan$plots$AxesSettings$GOFMergedPlotsResidualsOverTime)), + predictedVsObserved = list(axes = getAxesPropertiesFromName( + configurationPlan = configurationPlan, + plotName = "GOFMergedPlotsPredictedVsObserved" + )), + residualsOverTime = list(axes = getAxesPropertiesFromName( + configurationPlan = configurationPlan, + plotName = "GOFMergedPlotsResidualsOverTime" + )), digits = reEnv$formatNumericsDigits, nsmall = reEnv$formatNumericsSmall, scientific = reEnv$formatNumericsScientific @@ -1007,7 +1016,12 @@ loadQualificationComparisonTimeProfileTask <- function(workflow, configurationPl workflowFolder = workflow$workflowFolder, active = active, message = defaultWorkflowMessages$plotComparisonTimeProfiles, - settings = list(axes = getAxesProperties(configurationPlan$plots$AxesSettings$ComparisonTimeProfile)) + settings = list( + axes = getAxesPropertiesFromName( + configurationPlan = configurationPlan, + plotName = "ComparisonTimeProfile" + ) + ) )) } @@ -1049,7 +1063,10 @@ loadPlotPKRatioTask <- function(workflow, configurationPlan) { active = active, message = defaultWorkflowMessages$plotPKRatio, settings = list( - axes = getAxesProperties(configurationPlan$plots$AxesSettings$PKRatioPlots), + axes = getAxesPropertiesFromName( + configurationPlan = configurationPlan, + plotName = "PKRatioPlots" + ), digits = reEnv$formatNumericsDigits, nsmall = reEnv$formatNumericsSmall, scientific = reEnv$formatNumericsScientific, @@ -1115,8 +1132,14 @@ loadPlotDDIRatioTask <- function(workflow, configurationPlan) { active = active, message = defaultWorkflowMessages$plotDDIRatio, settings = list( - predictedVsObserved = list(axes = getAxesProperties(configurationPlan$plots$AxesSettings$DDIRatioPlotsPredictedVsObserved)), - residualsOverTime = list(axes = getAxesProperties(configurationPlan$plots$AxesSettings$DDIRatioPlotsResidualsVsObserved)), + predictedVsObserved = list(axes = getAxesPropertiesFromName( + configurationPlan = configurationPlan, + plotName = "DDIRatioPlotsPredictedVsObserved" + )), + residualsOverTime = list(axes = getAxesPropertiesFromName( + configurationPlan = configurationPlan, + plotName = "DDIRatioPlotsResidualsVsObserved" + )), digits = reEnv$formatNumericsDigits, nsmall = reEnv$formatNumericsSmall, scientific = reEnv$formatNumericsScientific diff --git a/inst/extdata/qualification-axis-settings.json b/inst/extdata/qualification-axis-settings.json new file mode 100644 index 000000000..55bf0b52a --- /dev/null +++ b/inst/extdata/qualification-axis-settings.json @@ -0,0 +1,114 @@ +{ + "GOFMergedPlotsPredictedVsObserved": [ + { + "Type": "X", + "Dimension": "Concentration (mass)", + "Unit": "µg/l", + "GridLines": false, + "Scaling": "Log" + }, + { + "Type": "Y", + "Dimension": "Concentration (mass)", + "Unit": "µg/l", + "GridLines": false, + "Scaling": "Log" + } + ], + "GOFMergedPlotsResidualsOverTime": [ + { + "Type": "X", + "Dimension": "Time", + "Unit": "h", + "GridLines": false, + "Scaling": "Linear" + }, + { + "Type": "Y", + "Dimension": "Dimensionless", + "Unit": "", + "GridLines": false, + "Scaling": "Linear" + } + ], + "ComparisonTimeProfile": [ + { + "Type": "X", + "Dimension": "Time", + "Unit": "h", + "GridLines": false, + "Scaling": "Linear" + }, + { + "Type": "Y", + "Dimension": "Concentration (mass)", + "Unit": "µg/l", + "GridLines": false, + "Scaling": "Log" + } + ], + "DDIRatioPlotsPredictedVsObserved": [ + { + "Type": "X", + "Dimension": "Dimensionless", + "Unit": "", + "GridLines": false, + "Scaling": "Log" + }, + { + "Type": "Y", + "Dimension": "Dimensionless", + "Unit": "", + "GridLines": false, + "Scaling": "Log" + } + ], + "DDIRatioPlotsResidualsVsObserved": [ + { + "Type": "X", + "Dimension": "Dimensionless", + "Unit": "", + "GridLines": false, + "Scaling": "Log" + }, + { + "Type": "Y", + "Dimension": "Dimensionless", + "Unit": "", + "GridLines": false, + "Scaling": "Log" + } + ], + "PKRatioPlots": [ + { + "Type": "X", + "Dimension": "Age", + "Unit": "year(s)", + "GridLines": false, + "Scaling": "Linear" + }, + { + "Type": "Y", + "Dimension": "Dimensionless", + "Unit": "", + "GridLines": false, + "Scaling": "Log" + } + ], + "TimeProfile": [ + { + "Type": "X", + "Dimension": "Time", + "Unit": "h", + "GridLines": false, + "Scaling": "Linear" + }, + { + "Type": "Y", + "Dimension": "Concentration (mass)", + "Unit": "µg/l", + "GridLines": false, + "Scaling": "Log" + } + ] +} diff --git a/man/formatAxisProperties.Rd b/man/formatAxisProperties.Rd new file mode 100644 index 000000000..7c2ddfb2a --- /dev/null +++ b/man/formatAxisProperties.Rd @@ -0,0 +1,18 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/utilities-configuration-plan.R +\name{formatAxisProperties} +\alias{formatAxisProperties} +\title{formatAxisProperties} +\usage{ +formatAxisProperties(axisField) +} +\arguments{ +\item{axisField}{List of configuration plan field properties} +} +\value{ +A list of properties compatible with `tlf` package nomenclature +} +\description{ +Format configuration plan field values to a list compatible with `tlf` package nomenclature +} +\keyword{internal} diff --git a/man/getAxesPropertiesFromName.Rd b/man/getAxesPropertiesFromName.Rd new file mode 100644 index 000000000..bd2f6423b --- /dev/null +++ b/man/getAxesPropertiesFromName.Rd @@ -0,0 +1,22 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/utilities-configuration-plan.R +\name{getAxesPropertiesFromName} +\alias{getAxesPropertiesFromName} +\title{getAxesPropertiesFromName} +\usage{ +getAxesPropertiesFromName(configurationPlan, plotName) +} +\arguments{ +\item{configurationPlan}{A `ConfigurationPlan` object} + +\item{plotName}{Field name of the plot in the configuration plan `AxesSettings`} +} +\value{ +A list of properties for axes identified for `x`, `y` and `y2` axes. +The identified properties are directly compatible with `tlf` package nomenclature +} +\description{ +Get axes properties from global field `AxesSettings` of configuration plan if defined, +otherwise use default values. +} +\keyword{internal} diff --git a/man/getDefaultTimeProfileAxesSettings.Rd b/man/getDefaultTimeProfileAxesSettings.Rd deleted file mode 100644 index 924b373e1..000000000 --- a/man/getDefaultTimeProfileAxesSettings.Rd +++ /dev/null @@ -1,16 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/qualification-time-profile.R -\name{getDefaultTimeProfileAxesSettings} -\alias{getDefaultTimeProfileAxesSettings} -\title{getDefaultTimeProfileAxesSettings} -\usage{ -getDefaultTimeProfileAxesSettings() -} -\value{ -List of `x` and `y` axes settings -} -\description{ -Get the default axes settings for mean and population time profiles -for keeping compatibility with configuration plan from Matlab version -} -\keyword{internal}