Overview

  • Reporting analyses has become very customizable with the help of R Markdown. Users can write code, text, and display results all within the same document.





  • There is a lot of customizability around how the report is displayed, such as whether or not the user wants to evaluate a certain chunk of code, or whether the user wants the chunk of code to be seen or not, etc.

Incorporating parameters into an R Markdown document can take customizability a step further.

Parameters allow users to run the same report across different scenarios:

  • Showing the results for different diagnoses

  • Selecting certain years for the report

  • Showing results under different assumptions

  • Changing the behavior of knitr

Incorporating Parameters

  • Parameters are incorporated into the YAML section of the R Markdown document in the 'params' field.
  • R types that can be parsed by yaml::yaml.load() can be included as parameters (character, numeric, integer, logical)

  • R objects can be included with '!r' before the R expression

Using Parameters

  • Parameters can be accessed within a read-only list called params.

  • Simply include 'params$' and the parameter to be accessed:

params$surgery
params$year
etc.


Knitting

  • Using the 'Knit' button in RStudio
  • Using 'rmarkdown::render()'



  • Using an interactive UI for input of parameter values

The UI

The graphical user interface is based on Shiny. It's used to interactively select inputs for the report.

It can be accessed by:

  • 'Knit' dropdown > 'Knit with Parameters' or

  • rmarkdown::render("My_Parameter_Document.Rmd", params="ask")

What if we wished to constrain 'year' to a certain range, or we wished to display discrete options for 'surgery'?

  • Inputs for parameters can be controlled by additional arguments in the YAML.

  • The graphical UI has the ability to provide different features for input selection such as sliders, check boxes, text boxes.

The Input field controls the type of feature. Below is a list of the different inputs currently supported.

To create these features, sub-items can be specified under the parameters in the YAML:

These interactive features are very helpful when others are accessing your report, such as with RStudio Connect (https://www.rstudio.com/products/connect/)

Resources