Takes the ui elements in the state and element and attempts to add a rule.
Arguments
- state
CTS state from
CTS_fetch_state()
- element
Element list from
CTS_fetch_current_element()
Value
Element with the results of adding the rule. The rares
list
element can be used to determine the exit status of the function.
RULE_IS_GOOD If true it indicates that the pieces of the rule from the UI check out.
RULE_UPDATED If RULE_IS_GOOD and RULE_UPDATED is true then a previous rule definition was overwritten. If RULE_IS_GOOD is TRUE and RULE_UPDATED is FALSE then a new rule was added.
notify_text Text for notify message
notify_id Notification ID
notify_type Notification type
msgs Vector of messages.
Details
This depends on the following UI values in the state and element
state[["CTS"]][["ui"]][["rule_name"]]
state[["CTS"]][["ui"]][["rule_condition"]]
state[["CTS"]][["ui"]][["rule_type"]]
For rule type "dose"
state[["CTS"]][["ui"]][["action_dosing_state"]]
state[["CTS"]][["ui"]][["action_dosing_values"]]
state[["CTS"]][["ui"]][["action_dosing_times"]]
state[["CTS"]][["ui"]][["action_dosing_durations"]]
For rule type "set state"
state[["CTS"]][["ui"]][["action_set_state_state"]]
state[["CTS"]][["ui"]][["action_set_state_values"]]
For rule type "manual code"
state[["CTS"]][["ui"]][["action_manual_code"]]
Examples
# For more information see the Clinical Trial Simulation vignette:
# https://ruminate.ubiquity.tools/articles/clinical_trial_simulation.html
# None of this will work if rxode2 isn't installed:
# \donttest{
library(formods)
if( Sys.getenv("ruminate_rxfamily_found") == "TRUE"){
# This will populate the session variable with the model building (MB) module
sess_res = MB_test_mksession()
session = sess_res[["session"]]
id = "CTS"
input = list()
# Configuration files
FM_yaml_file = system.file(package = "formods", "templates", "formods.yaml")
MOD_yaml_file = system.file(package = "ruminate", "templates", "CTS.yaml")
state = CTS_fetch_state(id = id,
input = input,
session = session,
FM_yaml_file = FM_yaml_file,
MOD_yaml_file = MOD_yaml_file,
react_state = NULL)
# Fetch a list of the current element
current_ele = CTS_fetch_current_element(state)
# You can modify the element
current_ele[["element_name"]] = "A more descriptive name"
# Defining the source model
state[["CTS"]][["ui"]][["source_model"]] = "MB_obj_1_rx"
current_ele = CTS_change_source_model(state, current_ele)
# Single visit
current_ele[["ui"]][["visit_times"]] = "0"
current_ele[["ui"]][["cts_config_nsteps"]] = "5"
# Creating a dosing rule
state[["CTS"]][["ui"]][["rule_condition"]] = "time == 0"
state[["CTS"]][["ui"]][["rule_type"]] = "dose"
state[["CTS"]][["ui"]][["action_dosing_state"]] = "central"
state[["CTS"]][["ui"]][["action_dosing_values"]] = "c(1)"
state[["CTS"]][["ui"]][["action_dosing_times"]] = "c(0)"
state[["CTS"]][["ui"]][["action_dosing_durations"]] = "c(0)"
state[["CTS"]][["ui"]][["rule_name"]] = "Single_Dose"
# Adding the rule:
current_ele = CTS_add_rule(state, current_ele)
# Appending the plotting details as well
current_ele[["ui"]][["fpage"]] = "1"
current_ele[["ui"]][["dvcols"]] = "Cc"
# Reducing the number of subjects and steps to speed things up on CRAN
current_ele[["ui"]][["nsub"]] = "2"
current_ele[["ui"]][["cts_config_nsteps"]] = "5"
# Putting the element back in the state forcing code generation
state = CTS_set_current_element(
state = state,
element = current_ele)
# Now we pull out the current element, and simulate it
current_ele = CTS_fetch_current_element(state)
#current_ele = CTS_simulate_element(state, current_ele)
# Next we plot the element
current_ele = CTS_plot_element(state, current_ele)
# Now we save those results back into the state:
state = CTS_set_current_element(
state = state,
element = current_ele)
# This will extract the code for the current module
code = CTS_fetch_code(state)
code
# This will update the checksum of the module state
state = CTS_update_checksum(state)
# Access the datasets generated from simulations
ds = CTS_fetch_ds(state)
# CTS_add_covariate
state[["CTS"]][["ui"]][["covariate_value"]] = "70, .1"
state[["CTS"]][["ui"]][["covariate_type_selected"]] = "cont_lognormal"
state[["CTS"]][["ui"]][["selected_covariate"]] = "WT"
current_ele = CTS_add_covariate(state, current_ele)
# Creates a new empty element
state = CTS_new_element(state)
# Delete the current element
state = CTS_del_current_element(state)
}
#> → ASM: including file
#> → ASM: source: file.path(system.file(package="onbrand"), "templates", "report.docx")
#> → ASM: dest: file.path("config","report.docx")
#> → ASM: including file
#> → ASM: source: file.path(system.file(package="onbrand"), "templates", "report.pptx")
#> → ASM: dest: file.path("config","report.pptx")
#> → ASM: including file
#> → ASM: source: file.path(system.file(package="onbrand"), "templates", "report.yaml")
#> → ASM: dest: file.path("config","report.yaml")
#> → ASM: State initialized
#> → ASM: setting word placeholders:
#> → ASM: -> setting docx ph: HEADERLEFT = left header
#> → ASM: -> setting docx ph: HEADERRIGHT = right header
#> → ASM: -> setting docx ph: FOOTERLEFT = left footer
#> → ASM: module isgood: TRUE
#> → MB: including file
#> → MB: source: file.path(system.file(package="onbrand"), "templates", "report.docx")
#> → MB: dest: file.path("config","report.docx")
#> → MB: including file
#> → MB: source: file.path(system.file(package="onbrand"), "templates", "report.pptx")
#> → MB: dest: file.path("config","report.pptx")
#> → MB: including file
#> → MB: source: file.path(system.file(package="onbrand"), "templates", "report.yaml")
#> → MB: dest: file.path("config","report.yaml")
#> ! MB: User-defined model: /Users/jmh/projects/ruminate/github/ruminate/docs/reference/user_model.R not found (skipping)
#> ! MB: User-defined model: /Users/jmh/projects/ruminate/github/ruminate/docs/reference/user_model.ctl not found (skipping)
#> → MB: module checksum updated:f7de2055542d3ff1b085fafc2d30a1f8
#> → MB: State initialized
#> → MB: loading model idx: 1
#>
#>
#> ℹ parameter labels from comments are typically ignored in non-interactive mode
#> ℹ Need to run with the source intact to parse comments
#> → MB: model checksum updated: 571d5db71604ebb2f45fd7e209f29116
#> → MB: module checksum updated:20ddfe603b5516518a3c0ff6a5b6f1ca
#>
#>
#> ℹ parameter labels from comments are typically ignored in non-interactive mode
#> ℹ Need to run with the source intact to parse comments
#> → MB: model checksum updated: d59bc32e4d6f71f789e8728589744a4c
#> → MB: module checksum updated:9c40b454af7b15b948f3ffd4af8caf05
#> → MB: -> setting name: One compartment model
#> → MB: -> setting time scale: hours
#> → MB: -> setting base from: user
#> → MB: -> setting catalog selection:
#> → MB: -> setting base model id: manual
#> → MB: -> setting base model name: manual
#> → MB: model checksum updated: 878d607111fd5323f29970ddf1f51979
#> → MB: module checksum updated:81ca5c5d651c5e8a03f6406e37c57020
#> → MB: added element idx: 1
#> → MB: loading model idx: 2
#>
#>
#> ℹ parameter labels from comments are typically ignored in non-interactive mode
#> ℹ Need to run with the source intact to parse comments
#> → MB: model checksum updated: cb223089ea5a98470ffc070859bf12c0
#> → MB: module checksum updated:8b59d491e1ded31d6063b14096e952a8
#> → MB: -> setting name: PK Biomarker
#> → MB: -> setting time scale: days
#> → MB: -> setting base from: user
#> → MB: -> setting catalog selection:
#> → MB: -> setting base model id: manual
#> → MB: -> setting base model name: manual
#> → MB: model checksum updated: fb52578029947694a3905fb23f895f03
#> → MB: module checksum updated:99570fc8330ca60d9a856d9037bfe2fe
#> → MB: added element idx: 2
#> → MB: module isgood: TRUE
#> → # preload_complete is good: TRUE ------------------------------------------
#> → CTS: including file
#> → CTS: source: file.path(system.file(package="onbrand"), "templates", "report.docx")
#> → CTS: dest: file.path("config","report.docx")
#> → CTS: including file
#> → CTS: source: file.path(system.file(package="onbrand"), "templates", "report.pptx")
#> → CTS: dest: file.path("config","report.pptx")
#> → CTS: including file
#> → CTS: source: file.path(system.file(package="onbrand"), "templates", "report.yaml")
#> → CTS: dest: file.path("config","report.yaml")
#> → CTS: source model change detected
#> → CTS: > covariates reset
#> → CTS: cohort checksum updated: e3a504297cfa1b82fac27fd5d15f9bc9
#> → CTS: module checksum updated: 12eee0aee603deb28efad29f9daf28d3
#> → CTS: State initialized
#> → CTS: add rule success
#> → CTS: rule added
#> → CTS: cohort checksum updated: 847862ad01fa5695d27d53185e6a420f
#> → CTS: module checksum updated: 0a5fc72ff10da99bee0c2788ba36ae67
#> → CTS: CTS_plot_element()
#> → CTS: # Plotting timecourse
#> → CTS: CTS_obj_1_fgtc =
#> → CTS: plot_sr_tc(sro = CTS_obj_1_simres,
#> → CTS: xcol = "time",
#> → CTS: xlab_str = "Time",
#> → CTS: fncol = 4,
#> → CTS: fnrow = 2,
#> → CTS: dvcols = "Cc",
#> → CTS: fpage = 1)
#> → CTS:
#> → CTS: # Plotting events
#> → CTS: CTS_obj_1_fgev =
#> → CTS: plot_sr_ev(sro = CTS_obj_1_simres,
#> → CTS: xcol = "time",
#> → CTS: xlab_str = "Time",
#> → CTS: fncol = 4,
#> → CTS: fnrow = 2,
#> → CTS: evplot = 1,
#> → CTS: fpage = 1)
#> → CTS: No simulation available, you need to run the simulation first.
#> → CTS: cohort checksum updated: 0496d50c352b732b0405c06f8e5a2c23
#> → CTS: module checksum updated: e977d0ddbc77255ff20a218f8ef89c38
#> → CTS: source model change detected
#> → CTS: > covariates reset
#> → CTS: cohort checksum updated: 1f1dd0813caf3deb0557dbfddf970a7a
#> → CTS: module checksum updated: 97e0e86edc4f11ab8d4b1471bb9b1ce6
# }