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

  1. 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:
if (!is.element("rmarkdown", installed.packages()))
    install.packages("rmarkdown", dep = T)
  1. 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:

Also there are Cheatsheets (they can be accessed through the Help menu!):

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.

  1. 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.

  1. Then change the 4th line from
  • from output: html_document
  • to output: pdf_document

and compile the document again to create a PDF file.

  1. 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