# Creation of a clinical data review report

#### Laure Cougnaud, Michela Pasetto

#### February 23, 2023

Utility functions are provided to create a standard clinical data review report. Please note that the examples in this section are only informative, and not evaluated in the vignette itself.

    library(clinDataReview)

# 1 Create an example report

To create your clinical data review report, we advise to start from a skeleton of such report, via:

    createClinDataReviewReportSkeleton()

This report is based on an example dataset (subset of the CDISC Pilot 01 dataset), available in the `clinUtils` package.

The report is created via:

    render_clinDataReviewReport()

You can further tailor the report to your dataset(s) of interest and sections of interest.

See the next sections for further informations.

# 2 File structure

## 2.1 Input

The input for the clinical data report consists of a set of Rmardown files and a `config` directory.

Rmd files

A set of Rmarkdown files in the working directory should be

- index.Rmd file, containing the front page of the document.
  This file should be formatted as a Rmarkdown report with YAML header, with `output` set to: `clinDataReview::gitbook_clinDataReview_report`

- multiple Rmd files, one for each chapter (or template for multiple chapters). These files can be included in a R package.

Config files

There should be a `config` directory containing:

- a general configuration file: config.yml with:

  - `pathDataFolder`: path to a directory containing input data in sas7bdat or xpt format
  - `patientProfilesPath`(optional) : path to a directory that will contain patient profiles (if they are created with the `patientProfilesTemplate.Rmd` template report)
  - `study` (optional): study name
  - `version` (optional): data version, e.g. batch

- a configuration file for each chapter, as: config-[chapterName].yml.
  This file should contain input parameters containing:

  - `template`: filename of the Rmd file to consider for this chapter
  - `templatePackage`: name of the R package where the Rmd should be extracted from.
    If not specified, the template Rmd file should be available in the input directory (`inputDir`).
  - template-specific parameters:
    For the template reports available in the `clinDataReview` package, these include:
    - `reportTitle`: chapter title, used for section header
    - `dataFileName`: filename of the dataset of interest for this chapter, e.g.: ‘adae.sas7bdat’
    - `reportTitleLevel`: integer with section level, e.g. 2
    - extra parameters, accessed inside the template via `params$`

Please see the section Template reports for details on the template reports.

## 2.2 Output

The clinical data report consists of a final report output and a set of intermediary results.

Final output

A final output folder (‘report’ by default) containing the:

- final clinical data report, in a set of multiple HTML files
- required Javascript libraries in the subfolder: ‘libs’
- any extra directories created during report execution, by default: ‘tables’ and ‘figures’ (`extraDirs` parameter)
- (optionally) a directory with patient profiles

Intermediary results

A folder of intermediary results (‘interim’ by default) containing:

- Markdown file(s) for each report part
  (one per `template`/`templatePackage` combination of the config file(s))
- associated rds file containing specification of the Javascript libraries (via `knit_meta` object) and session information required for each report part

# 3 Template reports

A set of template reports are available in the `clinDataReview` package itself.

The full list of the reports and the corresponding input parameters is available at:
`? `clinDataReview-templates`` (please note the backticks!).

To use a template available in the package for one of your report, your config file should contain the corresponding name of the template via the `template` tag and the `templatePackage` set to ‘clinDataReview’.

For example, to include a division in the report, your YAML config file should be formatted as:

    template: divisionTemplate.Rmd
    templatePackage: clinDataReview
    reportTitle: "Title for a chapter"
    reportTitleLevel: 1

Please note that you can create your own template reports and store it in your custom R package (in a ‘inst/template’ folder).

# 4 Render a clinical data review report

## 4.1 Production

### 4.1.1 Create a report for production

The function `render_clinDataReviewReport` renders a clinical data report for production.

    clinDataReview::render_clinDataReviewReport()

The `render_clinDataReviewReport` creates several html files, one per configuration file, split based on the `split_by` parameter.

To open the full report, the user should open the introduction.html file.

In case a lot of different html chapters are created, a landing page can be created to guide the end-user to the opening of the report.

### 4.1.2 Create redirect page

A convenient way to store all html files into one location, and have only one page to look for to open the report is the function:

    clinDataReview::createRedirectPage()

This function:

- stores all html files into a folder
- create a landing page next to the folder that allows the user to navigate through the report.

The default names of the folder and landing page are report_dependencies and report.html. The names can be changed by the user.

### 4.1.3 Convert to .aspx format

When reports are to be deployed and displayed as webpages on SharePoint, the function:

    clinDataReview::convertReportToAspx(reportDir = ".")

can be used to change all extensions and cross-links of all files within the reportDir to .aspx-format.

### 4.1.4 Zip and send the report to collaborators

A dedicated functionality is available to zip the report and send it to colleagues within the team.

Once a report has been rendered, the user can call:

    clinDataReview::zipClinDataReview()

This function zips the report, so that the analyses can be easily put as attachement in a mail/uploaded to a shared drive.

If the folder is not unzipped before opening the reports, a message in the browser reminds to unzip the documents.

### 4.1.5 Add metadata

Metadata can be added in the landing page, containing information concerning the data set creation time, the path to the original data etc.

A metadata file should be in yaml format.

The metadata function can be directly called in a Rmd documents with

    clinDataReview::getMetadata()

## 4.2 Development

To facilitate the creation of the report, a few utility functions & dedicated parameters are available.

### 4.2.1 Modular framework

#### 4.2.1.1 (Re-)run part(s) of the report

In case the creation of the entire report is time-consuming, and only part(s) of the report have been updated, it might be interesting to only re-run some parts of the report. Config files associated to the parts of the report that should be rerun can be specified via the `configFiles` parameter.

    # run one specific report
    clinDataReview::render_clinDataReviewReport(configFiles = "config-AE_timeprofile.yml")
    # only run the listings:
    clinDataReview::render_clinDataReviewReport(configFiles = list.files(pattern = "listing", "config"))

#### 4.2.1.2 Create the final clinical data report from the Markdown reports

To convert all created Markdown files to HTML, the dedicated function `postProcessReport` can be used.

    postProcessReport()

### 4.2.2 Debug a sub-report

To debug a sub-report, it might be interesting to run only one specific R report in the current R session, with the parameters provided by the associated config file. This can be achieved as followed:

    # get parameters from the general 'config.yml' and the specified config file
    params <- getParamsFromConfig(configFile = "config-AE_timeprofile.yml")

    # extract template from package if specified
    if(params$templatePackage == "clinDataReview"){
      pathTemplate <- clinDataReview::getPathTemplate(file = params$template)
      file.copy(from = pathTemplate, to = ".")
    }

    # run a current chapter (without clinical data Js libraries)
    # Note that Js library to have the functionality to download patient profiles is not imported
    rmarkdown::render(input = params$template)

    # preview a specific chapter (with clinical data Js libraries)
    bookdown::render_book(input = params$template, preview = TRUE)
    # include the index file:
    bookdown::render_book(input = c("index.Rmd", params$template), preview = TRUE)

## 4.3 Optimization for big clinical trial data

### 4.3.1 Optimize the report creation

The creation of the report can be time-consuming for big clinical trial data.

The creation of the report is speed up via the use of the `nCores` parameter. If specified, the creation of the Markdown file corresponding to each config file, and the creation of the HTML file for each (split) Markdown file are run in parallel.

    clinDataReview::render_clinDataReviewReport(nCores = 4)

### 4.3.2 Optimize the report loading time

The report can take some time to load in the browser for big clinical trial data.

The loading time can be improved by splitting the HTML page into smaller HTML pages, via the `split_by` parameter. This can be set at a level 7 of sectioning (level 1 corresponds to a chapter), and for a specific part of the report, corresponding to a specific config file.

    template: plotTemplate.Rmd
    templatePackage: clinDataReview
    reportTitle: 'Laboratory profiles'
    reportTitleLevel: 2
    split_by: 4
    loopingVar: ["LBCAT", "LBTEST"]

Example of config file with the use of the `split_by` parameter

In the example above, the report contains a section titled: ‘2.1 Laboratory profiles’ (level 2 of sectioning via the `reportTitleLevel` parameter), containing a subsection for each category of laboratory parameter (`LBCAT`) and a (nested) subsubsection for each laboratory test (`LBTEST`).
For example, this report can contain the subsubsection: ‘2.1.1.1 Alanine Aminotransferase’ with the laboratory profile for the Alanine Aminotransferase laboratory parameter.

This chapter is split at level 4 of sectioning: [level 2 for the title + 2 levels for the `loopingVar` variables], so the subsubsections containing the content for a laboratory parameter are available in separate HTML pages.

### 4.3.3 Optimize the report structure

In case a lot of sections with interactive plots are created via the `loopingVar` parameter, the table of contents can be quite extensive.

An alternative is to create a selection box (instead of a section) to select/filter the data of the plot based on grouping of a specific variable, via the `selectVars` parameter in the plotting function.

# 5 Appendix

## 5.1 Session info

R version 4.2.2 (2022-10-31) Platform: x86_64-pc-linux-gnu (64-bit) Running under: Ubuntu 22.04.1 LTS

Matrix products: default BLAS: /usr/lib/x86_64-linux-gnu/openblas-pthread/libblas.so.3 LAPACK: /usr/lib/x86_64-linux-gnu/openblas-pthread/libopenblasp-r0.3.20.so

locale: [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C LC_TIME=en_US.UTF-8 LC_COLLATE=C LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8
[7] LC_PAPER=en_US.UTF-8 LC_NAME=C LC_ADDRESS=C LC_TELEPHONE=C LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C

attached base packages: [1] stats graphics grDevices utils datasets methods base

other attached packages: [1] plyr_1.8.8 plotly_4.10.1 ggplot2_3.4.1 clinUtils_0.1.4 clinDataReview_1.4.0 knitr_1.42

loaded via a namespace (and not attached): [1] httr_1.4.4 sass_0.4.5 tidyr_1.3.0 jsonlite_1.8.4 viridisLite_0.4.1 bslib_0.4.2
[7] shiny_1.7.4 askpass_1.1 fontLiberation_0.1.0 ggrepel_0.9.3 yaml_2.3.7 gdtools_0.3.1
[13] pillar_1.8.1 glue_1.6.2 uuid_1.1-0 digest_0.6.31 promises_1.2.0.1 colorspace_2.1-0
[19] cowplot_1.1.1 htmltools_0.5.4 httpuv_1.6.9 gfonts_0.2.0 fontBitstreamVera_0.1.1 pkgconfig_2.0.3
[25] httpcode_0.3.0 haven_2.5.1 bookdown_0.32 purrr_1.0.1 xtable_1.8-4 scales_1.2.1
[31] inTextSummaryTable_3.2.1 later_1.3.0 officer_0.6.0 fontquiver_0.2.1 openssl_2.0.5 tibble_3.1.8
[37] generics_0.1.3 farver_2.1.1 ellipsis_0.3.2 DT_0.27 cachem_1.0.6 withr_2.5.0
[43] lazyeval_0.2.2 cli_3.6.0 magrittr_2.0.3 crayon_1.5.2 mime_0.12 memoise_2.0.1
[49] evaluate_0.20 fansi_1.0.4 forcats_1.0.0 xml2_1.3.3 tools_4.2.2 data.table_1.14.8
[55] hms_1.1.2 lifecycle_1.0.3 stringr_1.5.0 flextable_0.8.5 munsell_0.5.0 zip_2.2.2
[61] compiler_4.2.2 jquerylib_0.1.4 systemfonts_1.0.4 rlang_1.0.6 grid_4.2.2 htmlwidgets_1.6.1
[67] crosstalk_1.2.0 base64enc_0.1-3 labeling_0.4.2 rmarkdown_2.20 gtable_0.3.1 jsonvalidate_1.3.2
[73] curl_5.0.0 reshape2_1.4.4 R6_2.5.1 dplyr_1.1.0 fastmap_1.1.0 utf8_1.2.3
[79] stringi_1.7.12 parallel_4.2.2 crul_1.3 Rcpp_1.0.10 vctrs_0.5.2 tidyselect_1.2.0
[85] xfun_0.37