R Markdown is a format that allows you to combine text and R code. From RStudio you can output your file in many formats: html, PDF, Word, presentations. We are exploring a small slice of R Markdown. When you are ready to explore more, go to the R Markdown Definitive Guide.
Note, to make PDF files you will need a LaTeX installation. If you don’t have one already (if you are not sure, then you don’t), you can install tinytex. Run these lines:
install.packages('tinytex')
tinytex::install_tinytex()
Fork the repository Rmarkdown-Tutorial or download a zip file of the repository. To do the latter, you can use the ‘download zip file’ button on the GitHub repository or you can navigate to your ‘RWorkflow’ folder in RStudio and click ‘More’ in the Files panel and select ‘Set as working directory’. Then issue these commands.
library(RWorkflowsetup)
download.repo("Rmarkdown-Tutorial")
INCOIS participants: You will find a copy of the repository in the RWorkflow directory that you copied from the thumb drive.
Rmarkdown-Tutorial
and click Add Repository. If your forked the repository, you are done.Open up Basic.Rmd
.
At the top you see
---
title: "Basic"
author: "EE Holmes"
date: "9/2/2018"
output: html_document
---
This is the yaml
which gives the instructions about how to process your R Markdown file. The yaml
file is sensitive to spaces. Do not add or subtract spaces. This yaml
is very simple, but the yaml
can be complex for some applications. We will only be working with simple examples.
After the yaml
is the content. To see a summary of R Markdown formating, click ‘Help’ menu and then ‘Markdown Quick Reference’.
We can create documents in different formats from this Rmd file. Click the drop-down menu next to the ‘knit’ button.
In RStudio, click the ‘Help’ tab in the top nav bar. You will see ‘Markdown Quick Reference’. That has basic markdown syntax. You can also click ‘Cheatsheets’ and there are two references sheets. Using Google, you can also find answers to any questions that the RStudio help files doesn’t answer.
Tips:
Click the File tab, then select New File > R Markdown. This will open a template R Markdown file. You will be asked for a title and whether to have the output be html, PDF, or Word.
After knitting your Rmd file, a Preview will appear. Click the ‘Publish’ button in the top right, select ‘RPubs’. This is a free service for publishing output. Follow the instructions and you’ll soon have a link you can share. Here is a video showing how to do this.
If you have made your folder a Git repository, you can upload your html file to GitHub and share a link. We will cover that when we talk about websites on GitHub.
Figures.Rmd
Table.Rmd
Math.Rmd
Extras.Rmd
install.packages("xaringan")