Skip to content

Commit

Permalink
313 time offset (#651)
Browse files Browse the repository at this point in the history
* Fixes #313 time offset variable in simulation set for shifting time

While fixing this issue, I imported ospsuite.utils in NAMESPACE so ospsuite.utils:: should not be necessary any longer

* Integrate timeOffset in excel template

* Document timeOffset in vignette
  • Loading branch information
pchelle committed Jan 6, 2022
1 parent 426962f commit 9776ad2
Show file tree
Hide file tree
Showing 13 changed files with 331 additions and 145 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ export(updateSimulationIndividualParameters)
export(vpcParameterPlot)
import(ggplot2)
import(ospsuite)
import(ospsuite.utils)
import(stats)
import(tlf)
import(utils)
Expand Down
5 changes: 2 additions & 3 deletions R/messages.R
Original file line number Diff line number Diff line change
Expand Up @@ -180,11 +180,10 @@ messages <- list(
return(paste0(callingFunction(), "Values '", paste0(data[duplicated(data)], collapse = "', '"), "' in ", dataName, " are not unique"))
},

dataIncludedInTimeRange = function(finalSize, initialSize, timeRange, timeUnit, dataType) {
dataIncludedInTimeRange = function(finalSize, timeRange, timeUnit, dataType) {
paste0(
finalSize, " ", dataType,
" data were included in the analysis between ", min(timeRange), " and ", max(timeRange), " ", timeUnit,
". Initial size was ", initialSize, "."
" data were included in the analysis between ", min(timeRange), " and ", max(timeRange), " ", timeUnit, "."
)
}
)
Expand Down
14 changes: 7 additions & 7 deletions R/population-simulation-set.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#' @field studyDesignFile name of study design csv file
#' @field plotReferenceObsData logical for plotting reference observed data in Pediatric and Ratio Comparison workflows
#' @export
#' @importFrom ospsuite.utils %||%
#' @import ospsuite.utils
PopulationSimulationSet <- R6::R6Class(
"PopulationSimulationSet",
inherit = SimulationSet,
Expand Down Expand Up @@ -36,12 +36,12 @@ PopulationSimulationSet <- R6::R6Class(
studyDesignFile = NULL,
plotReferenceObsData = FALSE,
...) {
ospsuite.utils::validateIsLogical(referencePopulation)
ospsuite.utils::validateIsLogical(plotReferenceObsData)
ospsuite.utils::validateIsString(simulationSetName)
ospsuite.utils::validateIsString(simulationFile)
ospsuite.utils::validateIsString(populationFile)
ospsuite.utils::validateIsString(c(populationName, studyDesignFile), nullAllowed = TRUE)
validateIsLogical(referencePopulation)
validateIsLogical(plotReferenceObsData)
validateIsString(simulationSetName)
validateIsString(simulationFile)
validateIsString(populationFile)
validateIsString(c(populationName, studyDesignFile), nullAllowed = TRUE)
validateIsFileExtension(populationFile, "csv")

super$initialize(
Expand Down
47 changes: 26 additions & 21 deletions R/simulation-set.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@
#' @field timeUnit display unit for time variable
#' @field applicationRanges named list of logicals defining which Application ranges are included in
#' @field minimumSimulationEndTime is the minimum length of time for which a simulation must be run
#' @field timeOffset shift of display time in time profile plots
#' reported time profiles and residual plots when applicable
#' @export
#' @importFrom ospsuite.utils %||%
#' @import ospsuite.utils
SimulationSet <- R6::R6Class(
"SimulationSet",
public = list(
Expand All @@ -22,6 +23,7 @@ SimulationSet <- R6::R6Class(
timeUnit = NULL,
applicationRanges = NULL,
minimumSimulationEndTime = NULL,
timeOffset = NULL,

#' @description
#' Create a new `SimulationSet` object.
Expand All @@ -33,38 +35,41 @@ SimulationSet <- R6::R6Class(
#' @param timeUnit display unit for time variable. Default is "h"
#' @param applicationRanges names of application ranges to include in the report. Names are available in enum `ApplicationRanges`.
#' @param minimumSimulationEndTime is the minimum length of time for which a simulation must be run
#' @param timeOffset shift of display time in time profile plots
#' @return A new `SimulationSet` object
initialize = function(simulationSetName,
simulationFile,
outputs = NULL,
observedDataFile = NULL,
observedMetaDataFile = NULL,
timeUnit = "h",
applicationRanges = ApplicationRanges,
minimumSimulationEndTime = NULL) {
# Test and validate the simulation object
ospsuite.utils::validateIsString(simulationSetName)
ospsuite.utils::validateIsString(simulationFile)
simulationFile,
outputs = NULL,
observedDataFile = NULL,
observedMetaDataFile = NULL,
timeUnit = "h",
applicationRanges = ApplicationRanges,
minimumSimulationEndTime = NULL,
timeOffset = 0) {
# Test and validate the simulation objects
validateIsString(simulationSetName)
validateIsString(simulationFile)
validateIsFileExtension(simulationFile, "pkml")
validateIsString(c(observedDataFile, observedMetaDataFile, timeUnit), nullAllowed = TRUE)
validateIsPositive(object = minimumSimulationEndTime, nullAllowed = TRUE)
validateIsNumeric(timeOffset)
# For optional input, usually null is allowed
# but not here as it would mean that nothing would be reported
ospsuite.utils::validateIsIncluded(c(applicationRanges), ApplicationRanges)
validateIsIncluded(c(applicationRanges), ApplicationRanges)

validateIsFileExtension(simulationFile, "pkml")
simulation <- ospsuite::loadSimulation(simulationFile)

# Test and validate outputs and their paths
validateOutputObject(c(outputs), simulation, nullAllowed = TRUE)

validateIsPositive(object = minimumSimulationEndTime, nullAllowed = TRUE)
self$minimumSimulationEndTime <- minimumSimulationEndTime

# Test and validate observed data
ospsuite.utils::validateIsString(c(observedDataFile, observedMetaDataFile, timeUnit), nullAllowed = TRUE)
if (!is.null(observedDataFile)) {
validateObservedMetaDataFile(observedMetaDataFile, observedDataFile, c(outputs))
}

self$simulationSetName <- simulationSetName
self$simulationFile <- simulationFile
self$minimumSimulationEndTime <- minimumSimulationEndTime
self$timeOffset <- timeOffset

self$outputs <- c(outputs)

Expand All @@ -74,9 +79,9 @@ SimulationSet <- R6::R6Class(
self$timeUnit <- timeUnit %||% "h"

self$applicationRanges <- list(
total = ospsuite.utils::isIncluded(ApplicationRanges$total, applicationRanges),
firstApplication = ospsuite.utils::isIncluded(ApplicationRanges$firstApplication, applicationRanges),
lastApplication = ospsuite.utils::isIncluded(ApplicationRanges$lastApplication, applicationRanges)
total = isIncluded(ApplicationRanges$total, applicationRanges),
firstApplication = isIncluded(ApplicationRanges$firstApplication, applicationRanges),
lastApplication = isIncluded(ApplicationRanges$lastApplication, applicationRanges)
)
}
)
Expand Down
Loading

0 comments on commit 9776ad2

Please sign in to comment.