Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RStudio knitr themes

Tags:

r

rstudio

knitr

I've just started playing with some of the new knitr features in RStudio.

I've tried selecting several of the different themes in the R Markdown settings dialogue but these don't seem to have any noticeable impact on the style of my resulting document. Should it, or am I missing something? Everything just seems to come out in the default style no matter what theme I select.

---
output:
  html_document:
    number_sections: yes
    theme: spacelab
    toc: yes
  pdf_document: default
  word_document: default
---

R Markdown OptionsResult of export

Installation details:

  • R version 3.1.1
  • RStudio Version 0.98.977
  • knitr 1.6
  • rmarkdown 0.2.50
  • htmltools 0.2.4
  • Windows 7
like image 820
Tumbledown Avatar asked Jul 24 '14 13:07

Tumbledown


2 Answers

I had the same problem. Learning the following led me to the solution.

Two different things show up if you google "knitr theme".

  1. highlight parameter = syntax highlighting (1, 2, 3—familiar keywords like kate, tango, solarized-dark)
  2. theme parameter = bootswatch CSS (these are the less familiar keywords like spacelab, superhero, united, yeti)

Here are the instructions of how to add the correct knitr flags at the top of your .Rmd file.


Once you've added something like

---
title: "Impressive Client Report"
output:
  html_document:
    theme: spacelab
    highlight: neon
---

to the top, then open R in the directory where your .Rmd file lives, and run

require(knitr)
knit(input='impressive report.Rmd', output='impressive_report.Rhtml')

(I switched to _ because of another gotcha: I was switching between command-line R and RStudio knitting, not realising that RStudio was creating a different .html file to the one R was creating.)


Or in the case of RStudio, just Ctrl+Shift+K to knit your .Rmd file from the editing window—after changing both theme and highlight to valid values.

like image 175
isomorphismes Avatar answered Sep 22 '22 18:09

isomorphismes


I had this exact same problem and I was able to solve it by placing the theme argument before any other arguments. I am unsure if the order matters, but in my case it did. For example, this correctly changes my html theme:

---
title: "A Title"
author: "An Author"
date: "last update: `r format(Sys.Date(), format = '%d %B %Y')`" 
output: 
  html_document:
    theme: flatly
    highlight: haddock
    toc: true
    toc_float:
      collapsed: false
      smooth_scroll: true
---

While providing the theme argument towards the end did not work:

---
title: "A Title"
author: "An Author"
date: "last update: `r format(Sys.Date(), format = '%d %B %Y')`" 
output: 
  html_document:
    toc: true
    toc_float:
      collapsed: false
      smooth_scroll: true
  theme: flatly
  highlight: haddock
---

This also was true for my syntax highlighting argument.

like image 43
Matt Avatar answered Sep 23 '22 18:09

Matt