Chapter 11 Creating documents in RMarkdown
11.1 Overview
In this practical you will create an RMarkdown (.Rmd
) document in either html
or PDF
format. It can include anything, but I suggest you try to create a document that at least includes the following:
- text in paragraphs
- plots (eg scatterplots)
- maps
- tables
- some hidden code
- some visible code
NOTE
- you may have to install the
rmarkdown
package on University computers - you should not have to but You should test this by running the code:
- You may need to use a simply named folder. This means no non-text characters in the name. So
- not C:\Geocomp & Loc Anal\week9
- instead C:\Geocomp\week9
11.2 Resources
This tutorial https://rmarkdown.rstudio.com/articles_intro.html may help and some other potentially useful resources include:
- https://www.neonscience.org/rmd-code-intro
- https://rpubs.com/mnewco8290/94529
- http://www.jacolienvanrij.com/Tutorials/tutorialMarkdown.html
Also there are Cheatsheets (they can be accessed through the Help menu!):
- https://rmarkdown.rstudio.com/lesson-15.html
- https://www.rstudio.com/wp-content/uploads/2015/02/rmarkdown-cheatsheet.pdf
Documents created in this way allow you to connect the code, the analysis and the data in a single environment, supporting transparency and reproducibility.
11.3 Task
This just gets you to create, save and compile a simple R Markdown document.
- Open a new RMarkdown document:
File > New File > R Markdown
use HTML format.
Give it a name, save it and try to run it by clicking on the “knit” icon. If you get an error here, you probably need to install the rmarkdown
package for some reason.
- Then change the 4th line from
- from
output: html_document
- to
output: pdf_document
and compile the document again to create a PDF file.
- Go through the Rep_Example PDF and .Rmd files.
I have chopped down a GWR Practical as a short example as well as including the RMD file that made this document in the resources for this week.
You make sure that you can identify sections of words and code that produce text, plots, maps, hidden / visible code and tables as indicated above.
You should pay attention to the way that the code snippets presented, especially how the code blocks are bracketed by the commas.
You should try to create both PDF and HTML outputs by changing the below in the RMD header:
output: pdf_document
output: html_document