Advanced Economic Methods
Exercise 10: Creating an Rmarkdown document
Overview
The following tutorial will guide you through the development of an
Rmarkdown document. This will be the format of your final
exam.
Note: This document is in progress, and will be completed following the in-class tutorial
Step 1: Running your analysis
The easiest way to complete the document is to first prepare a normal
R script file and run all analyses required to complete
your project. Compiling an Rmarkdown file can be more
cumbersome if there are errors in your code. After you have a complete
analysis, you can copy/paste all your commands into the
Rmarkdown script and make the appropriate changes to have a
fully formatted html file.
Step 2: Install rmdformats
You will need a package to create the html documents.
Run this command in your console in the bottom left window of
Rstudio (not in your script file):
Step 3: Open an Rmarkdown document
Open a new script file, but be sure to select the correct one. It can be found at File -> New file -> R Markdown.
When opening the document, it will prompt you to enter a bunch of information and will create some text for you to use as a template. I prefer to delete all of this and start from scratch.
Step 4: Header and opening commands
The header is considerably different from a traditional script file, as this will contain all the information for the template of your choice, and all formatting commands. Here is a basic header you can copy/paste into your document:
---
title: 'Advanced Economic Methods'
subtitle: 'Final exam'
author: "Your Name"
date: "`r Sys.Date()`"
output:
rmdformats::downcute
---Notice that the title and subtitle should be in single quotation
marks, and the author and date are double quotation marks. The command
“`r Sys.Date()`” will extract the current date from your computer and
enter it into the document. You can also choose a fixed date
(e.g. "20.11.25"), but I prefer the system date so I can
keep track of when I last modified my work.
The output here uses the downcute format, but I
encourage you to explore different templates and choose one that you
prefer. You can find a gallery of templates here
There are plenty of additional options that you can experiment with.
I personally recommend using self-contained: true to bundle
everything into a single document, and you can explore the
highlight function to change the color of the code text.
Options include:
tangopygmentskatemonochromeespressozenburnhaddockbreezedarkhaskell