R Markdown Reports

Created by Chia, Jonathan, last modified on Apr 09, 2022

Introduction

Refer to this article when you want to organize a report that includes code

Table of Contents

Why Use R Markdown?

  1. Helps to keep your code organized

  2. Create clean reports where you can hide/show code when needed

  3. Can export as pdf, word, presentation, html, markdown, website, and dashboards

  4. Can create automated reports that get emailed to people

Template for HTML report

Below is the code from an R Markdown file that includes a table of contents (toc), adds code hide/show buttons (code_folding), and outputs as a html document



Output

Below is the output of the above code

Outputting to Word

Key packages:

  • Officedown

  • Officer

  • Flextable

  • htmlwidgets

  • pagedown

Officedown

Lets you adjust page margins, landscape, columns, and other Word specific options

Example:

Insert this code block below your outputs that you want to be in landscape mode

Officer

Officer has to be loaded to pair with officedown and flextable

Flextable

This package is so much better than DT package (unless you need DT for interactivity and filters)

Example:

Output:

HTML widgets and Pagedown to save HTML as picture

I use these two packages to save highcharter, ggplot, or plotly html charts as png files. Then I display the png in Word using include_graphics().

Example:

https://rmarkdown.rstudio.com/authoring_basics.html

https://bookdhttps://bookdown.org/yihui/rmarkdown/r-code.html own.org/yihui/rmarkdown/r-code.html

https://rmarkdown.rstudio.com/gallery.html

Random Useful Code

Widen the margins of the html output - really useful when you can't fit all your columns in your tables

Put this right after the yaml section:


Document generated by Confluence on Apr 09, 2022 02:02

Atlassian

Last updated