Skip to contents

Takes a CTS state and updates the checksum used to trigger downstream updates

Usage

CTS_update_checksum(state)

Arguments

state

CTS state from CTS_fetch_state()

Value

CTS state object with the checksum updated

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:
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=list(), full_session=FALSE)
session = sess_res[["session"]]

id     = "CTS"
id_ASM = "ASM"
id_MB  = "MB"
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,
                        id_ASM          = id_ASM,
                        id_MB           = id_MB,
                        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)
}
#> → 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:24933f86b657b9503f22440e8c4d3cac
#> → MB: State initialized
#> ! 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)
#>  
#>  
#>  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: 98407146cbcfb0e5392b7bf47aeb1d09
#> → MB: module checksum updated:a317b4031c8ca91b0c52f2a06412fe69
#> → 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: ad25a3c8c27bf31e142568d37ef09ca4
#> → CTS: module checksum updated: 8d03366b53c865cf49f7bd3b795fd398
#> → CTS: State initialized
#> → CTS: add rule success
#> → CTS: rule added
#> → CTS: cohort checksum updated: 3d23f9828639a27749b965fc4b700d1a
#> → CTS: module checksum updated: faada11c23e2b038e1f1142eba9a0e4c
#> → 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: c3336223d4b672759b83a11eda012600
#> → CTS: module checksum updated: d5a5bdeda1108d2fd47a0dc29c003e8f
#> → CTS: source model change detected
#> → CTS:  > covariates reset
#> → CTS: cohort checksum updated: e9791aa6fe7e9bf738b8b485992ba8f0
#> → CTS: module checksum updated: 55da72f1a6574fc5c9d5ae323c946147