RMarkdown and knitr presentation

Syntax

  • Header:
    • YAML format, used when the script is compile to define general parameter and metadata

Parameters

Parameterdefinition
titlethe title of the document
authorThe author of the document
dateThe date of the document: Can be "r format(Sys.time(), '%d %B, %Y')"
authorThe author of the document
outputThe output format of the document: at least 10 format available. For html document, html_output. For PDF document, pdf_document, ..

Remarks

Sub options parameters:

sub-optiondescriptionhtmlpdfwordodtrtfmdgithubioslidesslidybeamer
citation_packageThe LaTeX package to process citations, natbib, biblatex or noneXXX
code_foldingLet readers to toggle the display of R code, "none", "hide", or "show"X
colorthemeBeamer color theme to useX
cssCSS file to use to style documentXXX
devGraphics device to use for figure output (e.g. "png")XXXXXXX
durationAdd a countdown timer (in minutes) to footer of slidesX
fig_captionShould figures be rendered with captions?XXXXXXX
fig_height, fig_widthDefault figure height and width (in inches) for documentXXXXXXXXXX
highlightSyntax highlighting: "tango", "pygments", "kate","zenburn", "textmate"XXXXX
includesFile of content to place in document (in_header, before_body, after_body)XXXXXXXX
incrementalShould bullets appear one at a time (on presenter mouse clicks)?XXX
keep_mdSave a copy of .md file that contains knitr outputXXXXXX
keep_texSave a copy of .tex file that contains knitr outputXX
latex_engineEngine to render latex, or ""pdflatex", "xelatex", lualatex"XX
lib_dirDirectory of dependency files to use (Bootstrap, MathJax, etc.)XXX
mathjaxSet to local or a URL to use a local/URL version of MathJax to renderXXX
md_extensionsMarkdown extensions to add to default definition or R MarkdownXXXXXXXXXX
number_sectionsAdd section numbering to headersXX
pandoc_argsAdditional arguments to pass to PandocXXXXXXXXXX
preserve_yamlPreserve YAML front matter in final document?X
reference_docxdocx file whose styles should be copied when producing docx outputX
self_containedEmbed dependencies into the docXXX
slide_levelThe lowest heading level that defines individual slidesX
smallerUse the smaller font size in the presentation?X
smartConvert straight quotes to curly, dashes to em-dashes, ... to ellipses, etc.XXX
templatePandoc template to use when rendering fileXXXXX
themeBootswatch or Beamer theme to use for pageXX
tocAdd a table of contents at start of documentXXXXXXX
toc_depthThe lowest level of headings to add to table of contentsXXXXXX
toc_floatFloat the table of contents to the left of the main contentX

Adding a footer is not natively possible. Luckily, we can make use of jQuery and CSS to add a footer to the slides of an ioslides presentation rendered with knitr. First of all we have to include the jQuery plugin. This is done by the line

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js"></script>

Now we can use jQuery to alter the DOM (document object model) of our presentation. In other words: we alter the HTML structure of the document. As soon as the presentation is loaded ($(document).ready(function() { ... })), we select all slides, that do not have the class attributes .title-slide, .backdrop, or .segue and add the tag <footer></footer> right before each slide is 'closed' (so before </slide>). The attribute label carries the content that will be displayed later on.

All we have to do now is to layout our footer with CSS:

After each <footer> (footer::after):

  • display the content of the attribute label
  • use font size 12
  • position the footer (20 pixels from the bottom of the slide and 60 pxs from the left)

(the other properties can be ignored but might have to be modified if the presentation uses a different style template).

---
title: "Adding a footer to presentaion slides"
author: "Martin Schmelzer"
date: "26 Juli 2016"
output: ioslides_presentation
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
```

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js"></script>

<script>
    $(document).ready(function() {
      $('slide:not(.title-slide, .backdrop, .segue)').append('<footer label=\"My amazing footer!\"></footer>');    
    })
</script>

<style>
  footer:after {
    content: attr(label);
    font-size: 12pt;
    position: absolute;
    bottom: 20px;
    left: 60px;
    line-height: 1.9;
  }
</style>


## Slide 1

This is slide 1.

## Slide 2

This is slide 2

# Test

## Slide 3

And slide 3.

The result will look like this:

enter image description here

Rstudio example

This is a script saved as .Rmd, on the contrary of r scripts saved as .R.

To knit the script, either use the render function or use the shortcut button in Rstudio.

--- 
title: "Rstudio exemple of a rmd file"
author: 'stack user'
date: "22 July 2016"
output: html_document
---

The header is used to define the general parameters and the metadata.

## R Markdown

This is an R Markdown document.
It is a script written in markdown with the possibility to insert chunk of R code in it.
To insert R code, it needs to be encapsulated into inverted quote.

Like that for a long piece of code:

```{r cars}
summary(cars)
```

And like ``r cat("that")`` for small piece of code.

## Including Plots

You can also embed plots, for example:

```{r echo=FALSE}
plot(pressure)
```


2016-07-23
2016-07-26
R Language Pedia
Icon