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

Fixes #541 extend set parameter value by path #543

Merged
merged 1 commit into from
Jul 1, 2021
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
10 changes: 8 additions & 2 deletions R/utilities-parameter.R
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ setParameterValues <- function(parameters, values) {
#' of numeric values, if the value of more than one parameter should be changed. Must have the same
#' length as 'parameterPaths'
#' @param simulation Simulation uses to retrieve parameter instances from given paths.
#' @param stopIfNotFound Boolean. If \code{TRUE} (default) and no parameter exists for the given path,
#' an error is thrown. If \code{FALSE}, a warning is shown to the user
#'
#' @examples
#'
#' simPath <- system.file("extdata", "simple.pkml", package = "ospsuite")
Expand All @@ -119,9 +122,12 @@ setParameterValues <- function(parameters, values) {
#'
#' setParameterValuesByPath(c("Organism|Liver|Volume", "Organism|Volume"), c(2, 3), sim)
#' @export
setParameterValuesByPath <- function(parameterPaths, values, simulation) {
setParameterValuesByPath <- function(parameterPaths, values, simulation, stopIfNotFound = TRUE) {
setQuantityValuesByPath(
quantityPaths = parameterPaths, values = values, simulation = simulation
quantityPaths = parameterPaths,
values = values,
simulation = simulation,
stopIfNotFound = stopIfNotFound
)
}

Expand Down
12 changes: 9 additions & 3 deletions R/utilities-quantity.R
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ setQuantityValues <- function(quantities, values) {
#' of numeric values, if the value of more than one quantity should be changed. Must have the same
#' length as 'quantityPaths'
#' @param simulation Simulation uses to retrieve quantity instances from given paths.
#' @param stopIfNotFound Boolean. If \code{TRUE} (default) and no qyantuty exists for the given path,
#' an error is thrown. If \code{FALSE}, a warning is shown to the user

#' @examples
#'
#' simPath <- system.file("extdata", "simple.pkml", package = "ospsuite")
Expand All @@ -111,7 +114,7 @@ setQuantityValues <- function(quantities, values) {
#'
#' setParameterValuesByPath(list("Organism|Liver|Volume", "Organism|Liver|A"), c(2, 3), sim)
#' @export
setQuantityValuesByPath <- function(quantityPaths, values, simulation) {
setQuantityValuesByPath <- function(quantityPaths, values, simulation, stopIfNotFound = TRUE) {
validateIsString(quantityPaths)
validateIsNumeric(values)
validateIsSameLength(quantityPaths, values)
Expand All @@ -120,8 +123,11 @@ setQuantityValuesByPath <- function(quantityPaths, values, simulation) {
task <- getContainerTask()
for (i in seq_along(quantityPaths)) {
rClr::clrCall(
task, "SetValueByPath", simulation$ref,
enc2utf8(quantityPaths[[i]]), values[[i]]
task, "SetValueByPath",
simulation$ref,
enc2utf8(quantityPaths[[i]]),
values[[i]],
stopIfNotFound
)
}
}
Expand Down
Binary file modified inst/lib/OSPSuite.Assets.dll
Binary file not shown.
Binary file modified inst/lib/OSPSuite.Core.dll
Binary file not shown.
Binary file modified inst/lib/OSPSuite.Infrastructure.Autofac.dll
Binary file not shown.
Binary file modified inst/lib/OSPSuite.Infrastructure.Import.dll
Binary file not shown.
Binary file modified inst/lib/OSPSuite.Infrastructure.dll
Binary file not shown.
Binary file modified inst/lib/OSPSuite.R.dll
Binary file not shown.
12 changes: 6 additions & 6 deletions packages.config
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="OSPSuite.Assets" version="10.0.227"/>
<package id="OSPSuite.Core" version="10.0.227"/>
<package id="OSPSuite.Infrastructure" version="10.0.227"/>
<package id="OSPSuite.Infrastructure.Import" version="10.0.227"/>
<package id="OSPSuite.Infrastructure.Autofac" version="10.0.227"/>
<package id="OSPSuite.R" version="10.0.227"/>
<package id="OSPSuite.Assets" version="10.0.263"/>
<package id="OSPSuite.Core" version="10.0.263"/>
<package id="OSPSuite.Infrastructure" version="10.0.263"/>
<package id="OSPSuite.Infrastructure.Import" version="10.0.263"/>
<package id="OSPSuite.Infrastructure.Autofac" version="10.0.263"/>
<package id="OSPSuite.R" version="10.0.263"/>
<package id="OSPSuite.Serializer" version="3.0.0.1"/>
<package id="OSPSuite.Utility" version="4.0.0.4"/>
<package id="LumenWorksCsvReader" version="4.0.0"/>
Expand Down
8 changes: 8 additions & 0 deletions tests/testthat/test-utilities-quantity.R
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,11 @@ test_that("It throws an exception when setting values for a quantity that does n
parameterPath <- "Organism|Liver|NOPE|Volume"
expect_that(setQuantityValuesByPath(parameterPath, 100, sim), throws_error())
})

test_that("It does not throw an exception when setting values for a quantity that does not exist and the stopIfnotFound flag is set to false", {
sim <- loadTestSimulation("S1", loadFromCache = TRUE)
parameterPath <- "Organism|Liver|NOPE|Volume"
setQuantityValuesByPath(parameterPath, 100, sim, FALSE)
expect_false(is.null(sim))
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Yuri05 We need an expect for this test to be found .I just want to make sure that the line before does not throw

})