Skip to content

Commit

Permalink
Fixes Open-Systems-Pharmacology#755 add new function adjustTitlePage
Browse files Browse the repository at this point in the history
I named the object QualificationVersionInfo instead of VersionInfo.
I felt that VersionInfo was too vague
  • Loading branch information
pchelle committed Apr 8, 2022
1 parent aa4681a commit 13a1ed1
Show file tree
Hide file tree
Showing 8 changed files with 444 additions and 0 deletions.
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export(PopulationSimulationSet)
export(PopulationWorkflow)
export(PopulationWorkflowTypes)
export(QualificationTask)
export(QualificationVersionInfo)
export(QualificationWorkflow)
export(ResidualScales)
export(SensitivityPlotSettings)
Expand All @@ -34,6 +35,7 @@ export(addXParametersForDemogrpahyPlot)
export(addXParametersForPkParametersPlot)
export(addYParametersForDemogrpahyPlot)
export(addYParametersForPkParametersPlot)
export(adjustTitlePage)
export(analyzeCoreSensitivity)
export(analyzeSensitivity)
export(calculateArithmeticErrorRange)
Expand Down
141 changes: 141 additions & 0 deletions R/qualification-version-info.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
#' @title QualificationVersionInfo
#' @description Object defining Qualification Version Information to be displayed on title page
#' @field qualificationPlanRelease Qualification Plan Release Version (string, e.g. `"1.1"`)
#' @field osp OSP version (string, e.g. `"10.0"`)
#' @field qualificationFramework Qualification Framework version (string, e.g. `"3.0"`)
#' @export
#' @import ospsuite.utils
QualificationVersionInfo <- R6::R6Class(
"QualificationVersionInfo",
public = list(
qualificationPlanRelease = NULL,
osp = NULL,
qualificationFramework = NULL,

#' @description
#' Create a new `QualificationVersionInfo` object.
#' @param qualificationPlanRelease Qualification Plan Release Version (string, e.g. `"1.1"`)
#' @param osp OSP version (string, e.g. `"10.0"`)
#' @param qualificationFramework Qualification Framework version (string, e.g. `"3.0"`)
#' @return A new `QualificationVersionInfo` object
initialize = function(qualificationPlanRelease = NULL,
osp = NULL,
qualificationFramework = NULL) {
validateIsString(qualificationPlanRelease, nullAllowed = TRUE)
validateIsString(osp, nullAllowed = TRUE)
validateIsString(qualificationFramework, nullAllowed = TRUE)

# In gsub, character "." has a special meaning
# and needs to be escaped in the expression using "\\"
private$.qualificationPlanReleasePattern <- "x\\.x"
private$.ospPattern <- "y\\.y"
private$.qualificationFrameworkPattern <- "z\\.z"

self$qualificationPlanRelease <- qualificationPlanRelease
self$osp <- osp
self$qualificationFramework <- qualificationFramework
},

#' @description
#' Print version information
#' @return A text with system information
print = function() {
infoPrint <- c(
sprintf("Qualification Plan Release Version: %s", self$qualificationPlanRelease %||% ""),
sprintf("OSP version: %s", self$osp %||% ""),
sprintf("Qualification Framework version: %s", self$qualificationFramework %||% "")
)
cat(infoPrint, sep = "\n")
return(invisible(infoPrint))
},

#' @description
#' Update `text` if patterns of version info are found
#' @param text character string
#' @return Updated character string
updateText = function(text) {
eval(private$.updateExpression(c("qualificationPlanRelease", "osp", "qualificationFramework")))
return(text)
},

#' @description
#' Get the Qualification Plan Release Version pattern to be replaced in title page
#' **Caution, the function `gsub` is used to replace the pattern**
#' **Escape characters may be included in the pattern**
#' @return A character
getQualificationPlanReleasePattern = function() {
return(private$.getPattern("qualificationPlanRelease"))
},

#' @description
#' Get the OSP version pattern to be replaced in title page
#' **Caution, the function `gsub` is used to replace the pattern**
#' **Escape characters may be included in the pattern**
#' @return A character
getOSPPattern = function() {
return(private$.getPattern("osp"))
},

#' @description
#' Get the Qualification Framework version pattern to be replaced in title page
#' **Caution, the function `gsub` is used to replace the pattern**
#' **Escape characters may be included in the pattern**
#' @return A character
getQualificationFrameworkPattern = function() {
return(private$.getPattern("qualificationFramework"))
},

#' @description
#' Set the Qualification Plan Release Version pattern to be replaced in title page
#' **Caution, the function `gsub` is used to replace the pattern.**
#' **You may need to include escape characters in `pattern`**
#' @param pattern characters to be replaced in title page
setQualificationPlanReleasePattern = function(pattern) {
validateIsString(pattern)
private$.qualificationPlanRelease <- pattern
return(invisible())
},

#' @description
#' Set the OSP version pattern to be replaced in title page
#' **Caution, the function `gsub` is used to replace the pattern.**
#' **You may need to include escape characters in `pattern`**
#' @param pattern characters to be replaced in title page
setOSPPattern = function(pattern) {
validateIsString(pattern)
private$.osp <- pattern
return(invisible())
},

#' @description
#' Set the Qualification Framework version pattern to be replaced in title page
#' **Caution, the function `gsub` is used to replace the pattern.**
#' **You may need to include escape characters in `pattern`**
#' @param pattern characters to be replaced in title page
setQualificationFrameworkPattern = function(pattern) {
validateIsString(pattern)
private$.qualificationFrameworkPattern <- pattern
return(invisible())
}
),

private = list(
.qualificationPlanReleasePattern = NULL,
.ospPattern = NULL,
.qualificationFrameworkPattern = NULL,

.getPattern = function(field) {
# Return the value of a field to be passed on gsub pattern input
return(eval(parse(text = paste0("private$.", field, "Pattern"))))
},

.updateExpression = function(field) {
# Return expression to be evaluated that updates text based on version info
return(parse(text = paste0(
"if(!isEmpty(self$", field, ")){",
"text <- gsub(pattern = private$.", field, "Pattern, replacement = self$", field, ", x = text)",
"}"
)))
}
)
)
20 changes: 20 additions & 0 deletions R/utilities-writing-report.R
Original file line number Diff line number Diff line change
Expand Up @@ -445,3 +445,23 @@ getSimulationDescriptor <- function(workflow) {
validateIsOfType(workflow, "Workflow")
return(workflow$getSimulationDescriptor())
}

#' @title adjustTitlePage
#' @description Adust Qualification Version Information to be displayed on title page
#' @param fileName name of .md file to update
#' @param qualificationVersionInfo A `QualificationVersionInfo`object defining Qualification Version Information to be displayed on title page
#' @export
adjustTitlePage <- function(fileName, qualificationVersionInfo = NULL) {
validateIsOfType(qualificationVersionInfo, "QualificationVersionInfo", nullAllowed = TRUE)
# Does not adust title page if no QualificationVersionInfo
if(isEmpty(qualificationVersionInfo)){
return(invisible())
}
fileContent <- readLines(fileName, encoding = "UTF-8")
fileContent <- qualificationVersionInfo$updateText(fileContent)

fileObject <- file(fileName, encoding = "UTF-8")
write(fileContent, file = fileObject, sep = "\n")
close(fileObject)
return(invisible())
}
215 changes: 215 additions & 0 deletions man/QualificationVersionInfo.Rd

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

Loading

0 comments on commit 13a1ed1

Please sign in to comment.