Skip to contents

Generates a report from the states of the different modules. The type of report is based on the file extension of file_name.

Usage

FM_generate_report(
  state,
  session,
  file_dir,
  file_name,
  gen_code_only = FALSE,
  rpterrors = TRUE
)

Arguments

state

Module state requesting the report generation

session

Shiny session variable

file_dir

path to the location where the file should be written.

file_name

base_filename (acceptable extensions are xlsx, docx, or pptx).

gen_code_only

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

rpterrors

Boolean variable to generate reports with errors.

Value

List with the following elements

Details

This function will look through the loaded modules and find those with reporting enabbled. If reporting is enabled it will look for reporting functions for that module. Reporting functions should be of the following format (name and arguments):

XX_append_report(state, rpt, rpttype)

Where XX is the module short name. The state is the current state of the module. The rpt contains the current content of the report. This will vary based on the report type:

  • xlsx: List with two elements. The first is summary a data frame with two columns. The first column is called Sheet_Name and the second column is called Description. This is a catalog of sheets added to the report by the user and can be appended to using rbind. The second element in xlsx rpt is another list with element names corresponding to the report sheet names and the values corresponding to dataframes to be exported in the report.

  • pptx or docx: Corresponding onbrand reporting object.

Examples

# Within shiny both session and input variables will exist,
# this creates examples here for testing purposes:
sess_res = FG_test_mksession(session=list(), full_session=FALSE)
#> → UD: including file
#> → UD:   source: file.path(system.file(package="onbrand"), "templates", "report.docx")
#> → UD:   dest:   file.path("config","report.docx")
#> → UD: including file
#> → UD:   source: file.path(system.file(package="onbrand"), "templates", "report.pptx")
#> → UD:   dest:   file.path("config","report.pptx")
#> → UD: including file
#> → UD:   source: file.path(system.file(package="onbrand"), "templates", "report.yaml")
#> → UD:   dest:   file.path("config","report.yaml")
#> → UD: State initialized
#> → UD: module checksum updated:897d952fecbc804999396a96f9df4b20
#> → DW: including file
#> → DW:   source: file.path(system.file(package="onbrand"), "templates", "report.docx")
#> → DW:   dest:   file.path("config","report.docx")
#> → DW: including file
#> → DW:   source: file.path(system.file(package="onbrand"), "templates", "report.pptx")
#> → DW:   dest:   file.path("config","report.pptx")
#> → DW: including file
#> → DW:   source: file.path(system.file(package="onbrand"), "templates", "report.yaml")
#> → DW:   dest:   file.path("config","report.yaml")
#> → DW: State initialized
#> → DW: module checksum updated:5b0f0b05ee3ac7336a74c564bb6efdad
#> → DW: module checksum updated:65801ab4b3c645aabf7edf91fc2f0d2c
#> → DW: module checksum updated:7fb2dd3b16b1780c4c24f64d658dd7c7
#> → DW: module checksum updated:5ab04ea00be44c0040695a4ed6243c90
#> → DW: module checksum updated:960db107cfe9db93578f79f0ae6283e2
#> → DW: module checksum updated:f0b5d122dcb04f207cba233253b61c4b
#> → DW: module checksum updated:189ed77a84bd9fcdd7b26abff8bea34a
#> → DW: module checksum updated:669ec77d50652669cd3fcfd949469b37
#> → DW: module checksum updated:dd6cafa0be3b6b195d230a11e9f07f9f
#> → DW: module checksum updated:5c2022c376ca8f56b839347156559890
#> → DW: module checksum updated:43640500a04674debd8e2399056c384a
#> → DW: module checksum updated:f81c45ac1ef4e7b43153d8c8eaf7aed6
#> → DW: module checksum updated:207cde891d98e20c4afbb7fb5fb0aba2
#> → DW: module checksum updated:0a673e81c01cbbf33533dd65d6baf9e3
#> → DW: module checksum updated:af3f3aefd0115ed9dfdd4d6ef9d5182f
#> → DW: module checksum updated:b0ccaee21e859322df0bf79d00c4b347
#> → DW: module checksum updated:2d3d6e9e38be6dea813b2d4d679e34b5
#> → DW: module checksum updated:2b60dd49b48a4e65200dc7241ad270e3
#> → DW: module checksum updated:3c92f397181a4fcdbdf2bd7dd7425e77
#> → DW: module checksum updated:92b81d7573def603649370b87c123b55
#> → DW: module checksum updated:9210264aabc0339e832b0c6bcfda32af
#> → DW: module checksum updated:fe62fde1e7e738a1a35c479de9d5007b
#> → DW: module checksum updated:ff3edcd4c1e58c96ea2707361916ffbc
#> → DW: module checksum updated:b6cdfcef0432c5d9b1fa2bd46122ffa2
#> → DW: module checksum updated:4fa4283f1fd8fd6cf6e6e7df0669723a
#> → DW: module checksum updated:cf3e139cef554b2d09dca619ee6aff41
#> → DW: module checksum updated:a9154d91a9e4b5d21f9585a6f68dd083
#> → DW: module checksum updated:4b5c6ad66658ddfa92d10ae1b0b7afa8
#> → DW: module checksum updated:591ac875a490b66a1fa7f4e7d4ba1c62
#> → DW: module checksum updated:afa3ca309cc3e6a48f542f4e8eadd54a
#> → DW: module checksum updated:5c918dd4f53a4f1e56115abb09c4f332
#> → DW: module checksum updated:159ddf8c8cd26b178dfda5434bbecfa1
#> → DW: module checksum updated:8bb3c97e700998f2f73353189bd07831
#> → DW: module checksum updated:a1eceffec3ff7d9f9961683b3d07088b
#> → FG: including file
#> → FG:   source: file.path(system.file(package="onbrand"), "templates", "report.docx")
#> → FG:   dest:   file.path("config","report.docx")
#> → FG: including file
#> → FG:   source: file.path(system.file(package="onbrand"), "templates", "report.pptx")
#> → FG:   dest:   file.path("config","report.pptx")
#> → FG: including file
#> → FG:   source: file.path(system.file(package="onbrand"), "templates", "report.yaml")
#> → FG:   dest:   file.path("config","report.yaml")
#> → FG: State initialized
#> → FG: module checksum updated:49305b1f42ca13ff15881186db5740a2
#> → FG: module checksum updated:19beaceb1e2cc087b4d2e1dd41949299
#> → FG: module checksum updated:0ae8c71516680571f55c4d35fb2d002e
#> → FG: module checksum updated:90765b786d12acc774c3de092fb11029
session = sess_res$session
input   = sess_res$input

# This will create a populated FG state object:
state   = sess_res$state


# This is the directory to write the report:
file_dir = tempdir()

# This is the file name that determines the type of report to write:
file_name = "my_report.pptx"

rpt_res =
FM_generate_report(state         = state,
                   session       = session,
                   file_dir      = file_dir,
                   file_name     = file_name,
                   gen_code_only = TRUE,
                   rpterrors     = TRUE)
#> → FG:   Generating report: pptx
#> → FG:     appending report for module:DW id:DW priority:1
#> → FG:     appending report for module:FG id:FG priority:1

# This contains the exit status of the report generation
rpt_res$isgood
#> [1] TRUE

# This is the underlying code that was used to generate the report
cat(paste0(rpt_res$code, collapse="\n"))
#> rpt  = onbrand::read_template(
#>   template = file.path("config", "report.pptx"),
#>   mapping  = file.path("config", "report.yaml"))
#> # Figure Fig_1(1): Individual profiles by cohort                         
#> rpt  = onbrand::report_add_slide(rpt,                              
#>           template = "content_list",                               
#>           elements = list(                                         
#>             title        = list( content = "Individual profiles by cohort",             
#>                                  type    = "text"),                
#>             content_body = list( content = ( FG_myp_1 + ggforce::facet_wrap_paginate(vars(Cohort), nrow = 3, ncol = 4, page=1)),        
#>                                  type    = "ggplot")))               
#> # Figure Fig_1(2): Individual profiles by cohort                         
#> rpt  = onbrand::report_add_slide(rpt,                              
#>           template = "content_list",                               
#>           elements = list(                                         
#>             title        = list( content = "Individual profiles by cohort",             
#>                                  type    = "text"),                
#>             content_body = list( content = ( FG_myp_1 + ggforce::facet_wrap_paginate(vars(Cohort), nrow = 3, ncol = 4, page=2)),        
#>                                  type    = "ggplot")))               
#> onbrand::save_report(rpt, file.path("reports", "report.pptx"))