Skip to contents

Appends report elements to a formods report.

Usage

DM_append_report(state, rpt, rpttype, gen_code_only = FALSE)

Arguments

state

DM state from DM_fetch_state()

rpt

Report with the current content of the report which will be appended to in this function. For details on the structure see the documentation for template_details

rpttype

Type of report to generate (supported "xlsx", "pptx", "docx").

gen_code_only

Boolean value indicating that only code should be generated (FALSE).

Value

list containing the following elements

  • isgood: Return status of the function.

  • hasrptele: Boolean indicator if the module has any reportable elements.

  • code: Code to generate reporting elements.

  • msgs: Messages to be passed back to the user.

  • rpt: Report with any additions passed back to the user.

Examples

# We need a state object to use below
sess_res = DM_test_mksession()
#> → 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: f280116ab6b4488df6de76aff513a83f
#> → DM: State initialized
#> → DM: ds checksum updated: 641fcbc6616d24d05acded4317a3bb12
#> → DM: module checksum updated: 78099100dae67cc0fee50517ea72a920
#> → 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: e2e04c45683f84c60c45d00409fba9e5
#> → DM: module checksum updated: 30c5c769094461b8429ae74d945a7475
#> → DM: added element idx: 1
#> → DM: loading element idx: 2
#> → DM: ds checksum updated: 8296250b072c5a527415fcda84118523
#> → DM: module checksum updated: f84b69d910710d1811cf90dee31f4968
#> → DM: added element idx: 2
#> → DM: loading element idx: 3
#> → DM: ds checksum updated: 0a6ecb743d041d95d3a4c31251a4b380
#> → DM: module checksum updated: e1d55e01e27af5c7e30d25c39feb4496
#> → DM: added element idx: 3
#> → DM: loading element idx: 4
#> → DM: ds checksum updated: 056a606c1b528400c2cad8141941308e
#> → DM: module checksum updated: 4f5d9a166ead196b5a8f6cd1e4b0494c
#> → DM: added element idx: 4
#> → DM: module isgood: TRUE
#> → # preload_complete is good: TRUE ------------------------------------------
state = sess_res$state

rpt = list(summary = list(), sheets=list())

rpt_res = DM_append_report(state,
  rpt     = rpt,
  rpttype = "xlsx")

# Shows if report elements are present
rpt_res$hasrptele
#> [1] TRUE

# Code chunk to generate report element
cat(paste(rpt_res$code, collapse="\n"))
#> # Excel (from file)
#> rpt[["sheets"]][["DM_obj_1"]] <- DM_obj_1
#> rpt[["summary"]] <- rbind(rpt[["summary"]],
#>   data.frame(
#>     Sheet_Name="DM_obj_1",
#>     Description="Excel (from file)"
#>   )
#> )
#> 
#> # STDM PC (url)
#> rpt[["sheets"]][["DM_obj_2"]] <- DM_obj_2
#> rpt[["summary"]] <- rbind(rpt[["summary"]],
#>   data.frame(
#>     Sheet_Name="DM_obj_2",
#>     Description="STDM PC (url): PC"
#>   )
#> )
#> 
#> # STDM EX (url)
#> rpt[["sheets"]][["DM_obj_3"]] <- DM_obj_3
#> rpt[["summary"]] <- rbind(rpt[["summary"]],
#>   data.frame(
#>     Sheet_Name="DM_obj_3",
#>     Description="STDM EX (url): EX"
#>   )
#> )
#> 
#> # STDM DM (url)
#> rpt[["sheets"]][["DM_obj_5"]] <- DM_obj_5
#> rpt[["summary"]] <- rbind(rpt[["summary"]],
#>   data.frame(
#>     Sheet_Name="DM_obj_5",
#>     Description="STDM DM (url): DM"
#>   )
#> )

# Tabular summary of data views
rpt_res$rpt$summary
#>   Sheet_Name       Description
#> 1   DM_obj_1 Excel (from file)
#> 2   DM_obj_2 STDM PC (url): PC
#> 3   DM_obj_3 STDM EX (url): EX
#> 4   DM_obj_5 STDM DM (url): DM