---
title: "Writing your problem sets"
author: "Bernhard Bieri"
date: "`r Sys.Date()`"
output: rmarkdown::html_vignette
vignette: >
  %\VignetteIndexEntry{Writing your problem sets}
  %\VignetteEngine{knitr::rmarkdown}
  %\VignetteEncoding{UTF-8}
---

```{r global.options, include = FALSE}
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.align = 'center',
  fig.width = 6,
  fig.height = 4
)
```

```{r setup, include=FALSE}
pkgs <- c("iheiddown", "magrittr", "ggplot2")
lapply(pkgs, library, character.only = TRUE)
```

While `{iheiddown}`'s main aim is to assist students in writing their thesis, it
can also be used for shorter projects such as problem sets. This short article
will walk you through the process of using the problem set template.

## Installation

The installation process is the same than for the thesis template. You'll need
the following software:

1. Install [R](https://cran.r-project.org) and [R-Studio](https://posit.co/)
2. Install a LATEX distribution:
    - [For MacOS](https://www.tug.org/mactex/)
    - [For Windows](https://miktex.org/)
    - [For Linux](https://www.tug.org/texlive/)
3. Install `{iheiddown}` by typing the following command
`install.packages("iheiddown") ` in the R-Studio console. 

Note: typing `remotes::install_github("jhollway/iheiddown")` will provide you
with the latest version from GitHub.

## Create your first problem set 

Creating your first problem set is easy! Before we begin, we have to create a
new R project by clicking on the file tab in the
top of the RStudio window and following the instructions of the prompt that
appears. Now that we have created an R project for our presentation, we can open
a new R-Markdown file. To do this click on the "plus file" logo in the top left
corner and then on "R-Markdown".

```{r, echo = FALSE, out.width="80%", fig.cap="Step 1: Open a project"}
  knitr::include_graphics("images/problemset/0-Open_Project.png", dpi = 144)
```

After you have done this, a little pop-up helper will appear. The first thing we
will do is to select the `{iheiddown}` template for our presentation. To do so,
click on the "From Template" option on the left and select the
"Problem Set {iheiddown}" template. Now give your file a name and click
on "OK".

```{r, echo = FALSE, out.width="80%", fig.cap="Step 2: Select a template"}
  knitr::include_graphics("images/problemset/1-Create_PS.png", dpi = 144)
```

Congrats! You just created your first problem set! We can actually already
render our problem set. This is done by simply clicking the "knit button"
while viewing the `MyProblemSet.Rmd` pane. Et voilà! You have now successfully
generated your first problem set with R.

Take a moment to read through the generated problem set to get acquainted
with the `{R-markdown}` syntax and to get a feel of the possibilities of the
`{iheiddown}` theme.

## Edit your problem set

This section will focus on giving you an overview of the workflow of writing
your problem sets in R with`{iheiddown}`.

### Set YAML options

The general options are set in the YAML header. You can define the metadata such
as the name of the authors, the course code *(required for the file name)*, and
the course name.

You can also set bibliographic options such as the `.bib` file you want to draw
your references from (`references.bib` by default) and the style of the
bibliographic entries by altering the `.csl` file. Note that packages that were
used in the code chunks of your problem set have their citation information
automatically written to a second `.bib` file called `packages.bib`. That way
you easily give appropriate credit to the work of the creators of the packages
you use.

That's it! You're now all set to focus on the content of your problem sets.
Again, please take a moment to read through the problem set template once it
is generated as it serves as much as a tutorial than this vignette.

### Understanding the appendix section

You might have spotted a somewhat unusual code chunk at the end of the file in
the appendix section. 

````markdown
`r ''````{r ref.label=knitr::all_labels(), echo=TRUE, eval=FALSE}
````

This special code chunk displays all the code you ran neatly at the end of your
analysis. This will help you keep your problem sets clean while still providing
your reader with a high level of transparency on how you manipulated your data
and created your output.
