Fiona Spooner
14th February 2018
Web pages
Word documents
PDFs
Presentations (like this!)
Books (see Hadley Wickham’s book on Data Science)
Similar to a regular R document except the code is broken up into chunks to which you can apply different options. For example, you can choose to execute a chunk of code but not to display it in the report by selecting the option ‘echo = FALSE’
Outside of the chunks you can add headers, pictures, links or text explaining your code
To use it you need:
RStudio
Packages ‘rmarkdown’ & ‘prettydoc’
Google the R Markdown cheat sheet
Not necessary now but if you want to produce PDFs then you will need LaTeX software:
Windows: MiKTeX - https://miktex.org/
Mac: BasicTeX - http://www.tug.org/mactex/morepackages.html
Once you have downloaded and installed everything you are ready to create an R Markdown document.
In RStudio go to:
File -> New File -> R Markdown….
Give it a name and select html as the default output format
This will open an R Markdown document with some default information included and some chunks set up:
The first chunk is the setup chunk, you can use this load libraries, functions and data
You can use {r, eval = FALSE} to skip chunks that take a long time to run and {r, echo = FALSE} to run chunks but not show the code in the output
There are lots of other options you can set at the beginning of each chunk - have a look at the R Markdown cheat sheet
You can have headers for each section by using “#”, the more you use (up to 6), the smaller your header is
These headers are collected into a table of contents you can use to navigate through your code - you can find this in the bottom-left and top-right corners of the script window
Once you have knitted your html document you will be able to publish it online at rpubs.com
If you want to make your knitted html a bit fancier you can use a prettydoc template
To do this replace output: html_document with: