Skip to contents

Appends a new empty ds to the DM state object and makes this new ds the active ds.

Usage

DM_new_element(state)

Arguments

state

DM state from DM_fetch_state()

Value

DM state object containing a new ds and that ds is set as the current active ds. See the help for DM_fetch_state() for ds format.

Examples

# Within shiny both session and input variables will exist,
# this creates examples here for testing purposes:
sess_res = DM_test_mksession(session=list())
#> → 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
#> → DM: including file
#> → DM:   source: file.path(system.file(package="onbrand"), "templates", "report.docx")
#> → DM:   dest:   file.path("config","report.docx")
#> → DM: including file
#> → DM:   source: file.path(system.file(package="onbrand"), "templates", "report.pptx")
#> → DM:   dest:   file.path("config","report.pptx")
#> → DM: including file
#> → DM:   source: file.path(system.file(package="onbrand"), "templates", "report.yaml")
#> → DM:   dest:   file.path("config","report.yaml")
#> → DM: module checksum updated: 441abbd92e02d893eb5136ccdfcc717d
#> → DM: State initialized
#> → DM: ds checksum updated: 641fcbc6616d24d05acded4317a3bb12
#> → DM: module checksum updated: 5c077c5702479f330bf233040eb4a51b
#> → DM: adding preload sources
#> → DM:  - file added: TEST_DATA.xlsx
#> → DM: added: TEST_DATA.xlsx
#> → DM:  - url added: https://raw.githubusercontent.com/john-harrold/formods/refs/heads/master/inst/test_data/SDTM_PC.csv
#> → DM: url added: https://raw.githubusercontent.com/john-harrold/formods/refs/heads/master/inst/test_data/SDTM_PC.csv
#> → DM:  - url added: https://raw.githubusercontent.com/john-harrold/formods/refs/heads/master/inst/test_data/SDTM_EX.csv
#> → DM: url added: https://raw.githubusercontent.com/john-harrold/formods/refs/heads/master/inst/test_data/SDTM_EX.csv
#> → DM:  - url added: https://raw.githubusercontent.com/john-harrold/formods/refs/heads/master/inst/test_data/SDTM_DM.csv
#> → DM: url added: https://raw.githubusercontent.com/john-harrold/formods/refs/heads/master/inst/test_data/SDTM_DM.csv
#> → DM: loading element idx: 1
#> → DM: ds checksum updated: 90805ca6c41a39696e1572d9b0a75868
#> → DM: module checksum updated: e23d5c825540acc0ebc26cb74c8b151a
#> → DM: added element idx: 1
#> → DM: loading element idx: 2
#> → DM: ds checksum updated: bc7f21be7671616bc4c9424ca2e20c15
#> → DM: module checksum updated: 10cf5bb1ef53dd5f9c334159edca1f4d
#> → DM: added element idx: 2
#> → DM: loading element idx: 3
#> → DM: ds checksum updated: 7139f90f0a927b1545a931a15d1ba097
#> → DM: module checksum updated: f1bb4b4c21d432a9b0469902d25353a4
#> → DM: added element idx: 3
#> → DM: loading element idx: 4
#> → DM: ds checksum updated: f197b4375f736ec7285315824f51f5c9
#> → DM: module checksum updated: adc4ce8011d1973150321257e21c8689
#> → DM: added element idx: 4
#> → DM: module isgood: TRUE
#> → # preload_complete is good: TRUE ------------------------------------------
state   = sess_res$state
session = sess_res$session
input   = sess_res$input

# Creates a new empty element
state = DM_new_element(state)

# Delete the current element
state = DM_del_current_element(state)

# Fetch a list of the current element
element = DM_fetch_current_element(state)

# You can modify the element
element[["name"]] = "A more descriptive name"

# You can now place element back in the state
state = DM_set_current_element(state, element)
#> → DM: ds checksum updated: 0ba4076a03db81b532093f502abd48b8
#> → DM: module checksum updated: 28e7bf24618fd53347e5f2eb4411e265

# This will pull the portion of the code associated with this module.
code = DM_fetch_code(state)

cat(code)
#> # Excel (from file) =======================================================
#> DM_obj_1 = rio::import(file="data/DM/TEST_DATA.xlsx", which ="DATA")
#> DM_obj_1 = janitor::clean_names(DM_obj_1, case="none")
#> # STDM PC (url) ===========================================================
#> DM_obj_2 = rio::import(file="https://raw.githubusercontent.com/john-harrold/formods/refs/heads/master/inst/test_data/SDTM_PC.csv")
#> DM_obj_2 = janitor::clean_names(DM_obj_2, case="none")
#> # STDM EX (url) ===========================================================
#> DM_obj_3 = rio::import(file="https://raw.githubusercontent.com/john-harrold/formods/refs/heads/master/inst/test_data/SDTM_EX.csv")
#> DM_obj_3 = janitor::clean_names(DM_obj_3, case="none")
#> # STDM DM (url) ===========================================================
#> DM_obj_5 = rio::import(file="https://raw.githubusercontent.com/john-harrold/formods/refs/heads/master/inst/test_data/SDTM_DM.csv")
#> DM_obj_5 = janitor::clean_names(DM_obj_5, case="none")

# This forces and update of the module checksum
state = DM_update_checksum(state)