copyWorksetParameterFromRun {openMpp}R Documentation

Copy parameters to working set from existing model run


Copy parameters to working set from existing model run with new value notes


copyWorksetParameterFromRun(dbCon, defRs, worksetId, baseRunId, ...)



database connection


model definition: database rows describing model input parameters and output tables


id of parameters working set, must be positive integer


id of model run results, must be positive integer


list of parameters value and value notes.

Each element is also a list of $name, $subCount, $subId, $value, $txt:

  • $name parameter name (character)

  • $txt (optional) workset parameter text: data frame with $lang = language code and $note = value notes


That call allow you to add a copy of input parameter value from existing model run into workset and update value notes.

Parameter(s) can have can have multiple sub-values (by default only one value, no sub-values). All parameter sub-values are copied from existing model run.

Workset is a working set of model parameters and can be a full set, which include values of all model parameters or subset and include only some parameters.

Each model must have "default" workset. Default workset is a first workset of the model with set_id = min(set_id) for that model. Default workset always include ALL model parameters (it is a full set).

If you want to create new workset as a full set of model parameters then you must pass ALL model parameters into createWorkset through ... argument list.

If you already have result of model run in your database and want to modify only some input parameters (subset) then call createWorksetBasedOnRun in order to create workset using parameters from previous model run and supply some new values.

You can create subset of model parameters ONLY based on existing run results. Otherwise you have to pass ALL (full set) of parameters in order to create workset.

Each workset has unique set id (positive integer) and also may have a name. To find set id by name use getWorksetIdByName call.

Working set must be not read-only in order to add parameters by copyWorksetParameterFromRun. And working set must be read-only to run the model, so, typically you want to wrap copyWorksetParameterFromRun by setReadonlyWorkset calls.

You must use getModel function in order to find model definition defRs.


Return id of working set or 0L on error


To run examples you must have modelOne database modelOne.sqlite in current directory




OpenM++ documentation:

See Also

getModel getFirstRunId getLastRunId getDefaultWorksetId getWorksetIdByName createWorkset createWorksetBasedOnRun setReadonlyWorkset setReadonlyDefaultWorkset updateWorksetParameter


  # model parameters:
  #   age by sex parameter double[4, 2] 
  #   salary by age parameter int[3, 4]
  #   starting seed parameter integer value
  # name, description and notes for this set of model parameters
  inputSet <- data.frame(
    name = "myOtherData",
    lang = "EN",
    descr = "new set of parameters",
    note = "new set of parameters with updated salary by age",
    stringsAsFactors = FALSE

  # age by sex parameter value notes
  ageSex <- list(
    name = "ageSex",    # parameter name
    txt = data.frame(
      lang = c("EN", "FR"),
      note = c(
        "age by sex value notes", # EN value notes
        NA                        # NA == no FR value notes 
      stringsAsFactors = FALSE
  theDb <- dbConnect(RSQLite::SQLite(), "modelOne.sqlite", synchronous = "full")
  invisible(dbGetQuery(theDb, "PRAGMA busy_timeout = 86400")) # recommended
  # get model by name: use such call if you have only one version of the model
  defRs <- getModel(theDb, "modelOne")
  # create new working set
  # for all parameters use previous model run with id = 101 
  setId <- createWorksetBasedOnRun(theDb, defRs, 101L, inputSet)
  if (setId <= 0L) stop("workset creation failed: ", defRs$modelDic$model_name, " ", defRs$modelDic$model_digest)
  # copy ageSex parameter value from model run with id = 102
  copyWorksetParameterFromRun(theDb, defRs, setId, 102L, ageSex)
  # make workset read-only in order to run the model
  setReadonlyWorkset(theDb, defRs, TRUE, setId)
  # you can run the model now with new ageSex parameter value

[Package openMpp version 0.8.6 Index]