cleanrmd

Clean HTML R Markdown Documents

Updated: May 19, 2023
Version: 0.1.1

Garrick Aden-Buie

cleanrmd is…

A collection of clean R Markdown HTML document templates using classy-looking classless CSS styles.

Sometimes you want to create a simple HTML file from your R Markdown source. You want something small to share with collaborators. You want a simple, readable document that you can email or just push to the web.

cleanrmd gives you a small, responsive HTML file that works great with R Markdown and pandoc and doesn’t rely on classes for styling so that it works in practically any browser.

Just because cleanrmd doesn’t use classes doesn’t mean you don’t have to! Feel free to use these themes as a starting point to add your own style and customization.

It’s still R Markdown

This is an R Markdown document. (View the source for this file.) Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.

Installation

You can install the released version of cleanrmd from CRAN:

install.packages("cleanrmd")

You can install the latest development version from GitHub:

# install.packages("remotes")
remotes::install_github("gadenbuie/cleanrmd")

or from gadenbuie.r-universe.dev:

options(repos = c(
  gadenbuie = 'https://gadenbuie.r-universe.dev',
  CRAN = 'https://cloud.r-project.org'
))

install.packages('cleanrmd')

Usage

cleanrmd::html_document_clean

Create a new R Markdown document using the Clean HTML R Markdown template in RStudio, or add the following to your .Rmd YAML header to use cleanrmd::html_document_clean.

output: 
  cleanrmd::html_document_clean:
    theme: no-class

To explore the available themes, set theme to NULL.

output: 
  cleanrmd::html_document_clean:
    theme: NULL

Syntax highlighting is provided by default by pandoc, where syntax highlighting is performed during during the render, minimizing dependencies. pandoc’s highlighting themes include pygments, tango, espresso, zenburn, kate, monochrome, breezedark, and haddock. The default highlighting theme is arrow, provided by the rmarkdown package in addition to the rstudio theme.

html_document_clean() can also use Prism for highlighting. In this case, highlighting is performed in the browser and the dependencies are downloaded as needed. To use Prism, set theme: prism or use one of the following value to choose a specific Prism theme: prism-coy, prism-dark, prism-funky, prism-okaidia, prism-solarizedlight, prism-tomorrow, and prism-twilight.

MathJax and FontAwesome are also available but disabled by default. To enable either feature, you can set mathjax to local or default, as in rmarkdown::html_document(). Set use_fontawesome to TRUE to enable Font Awesome icons.

output: 
  cleanrmd::html_document_clean:
    mathjax: default
    use_fontawesome: true

Just the theme

You can also load the CSS theme dependencies in other places where htmltools can be used to provide HTML dependencies, such as Shiny apps.

To include a theme in your app or page, use

cleanrmd::use_cleanrmd(theme = "new.css")

To view the list of theme options view the help pages of cleanrmd_themes() or use its output:

cleanrmd::cleanrmd_themes()
##  [1] "almond"            "awsm.css"          "axist"            
##  [4] "bamboo"            "bullframe"         "holiday"          
##  [7] "kacit"             "latex.css"         "markdown-splendor"
## [10] "markdown-retro"    "markdown-air"      "markdown-modest"  
## [13] "marx"              "minicss"           "new.css"          
## [16] "no-class"          "picocss"           "sakura"           
## [19] "sakura-vader"      "semantic"          "simplecss"        
## [22] "style-sans"        "style-serif"       "stylize"          
## [25] "superstylin"       "tacit"             "vanilla"          
## [28] "water"             "water-dark"        "writ"

Themes

The following CSS themes are included in this package and you can preview all 30 themes in one place here.


R Code

When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:

mtcars <- mtcars[, c("mpg", "cyl", "wt", "qsec")]
summary(mtcars)
##       mpg             cyl              wt             qsec      
##  Min.   :10.40   Min.   :4.000   Min.   :1.513   Min.   :14.50  
##  1st Qu.:15.43   1st Qu.:4.000   1st Qu.:2.581   1st Qu.:16.89  
##  Median :19.20   Median :6.000   Median :3.325   Median :17.71  
##  Mean   :20.09   Mean   :6.188   Mean   :3.217   Mean   :17.85  
##  3rd Qu.:22.80   3rd Qu.:8.000   3rd Qu.:3.610   3rd Qu.:18.90  
##  Max.   :33.90   Max.   :8.000   Max.   :5.424   Max.   :22.90

Plots

You can also embed plots, for example:

plot(mtcars$wt, mtcars$mpg, col = mtcars$cyl, pch = 16)

Tables

knitr::kable(mtcars[1:6, ], caption = "A subset of mtcars")
A subset of mtcars
mpg cyl wt qsec
Mazda RX4 21.0 6 2.620 16.46
Mazda RX4 Wag 21.0 6 2.875 17.02
Datsun 710 22.8 4 2.320 18.61
Hornet 4 Drive 21.4 6 3.215 19.44
Hornet Sportabout 18.7 8 3.440 17.02
Valiant 18.1 6 3.460 20.22

Headers (Header 2)

Header 3

Header 4

Header 5

Header 6

Block Quotes

We know from the Markdown syntax that paragraphs that start with > are converted to block quotes.

“If it weren’t for my lawyer, I’d still be in prison. It went a lot faster with two people digging.”

— Joe Martin

“Great people talk about ideas, average people talk about things, and small people talk about wine.”

— Fran Lebowitz

Images

Is it safe to come out yet? Photo by Mikhail Vasilyev on Unsplash.

Lists

Lorem ipsum dolor sit amet consectetur adipiscing elit torquent posuere penatibus ullamcorper, primis feugiat gravida risus phasellus placerat duis blandit elementum cubilia, mus porta ante fringilla etiam condimentum consequat imperdiet quisque netus.

Mattis varius conubia ornare turpis interdum laoreet, duis iaculis torquent purus ut id, parturient aptent luctus curae vel. Odio blandit dis proin quis ullamcorper sapien imperdiet lacus, neque per eros a posuere donec mauris purus, cursus potenti et auctor himenaeos aliquet diam.

  1. Lorem ipsum dolor sit amet consectetur, adipiscing elit pretium.
  2. Habitant interdum egestas pellentesque pharetra rutrum, ornare nisi netus luctus.
  3. Euismod convallis rutrum fermentum sodales hac, magna tristique mollis lacinia.
  4. Habitant nisi orci ad imperdiet sollicitudin, eu egestas sociosqu.