These instructions are heavily based on the instructions created by Dr. Gordan Zitkovic.
These instructions apply to the code-oriented parts of your homework assignments and to your projects. For the “theoretical” parts of your assignments, while it would be beneficial for you to learn how to type them up, you are allowed to write your solutions, scan your write-up, and upload the pdf file.
You need to have some version of LaTeX installed on your computer. You will not need to learn LaTeX. It is simply needed (behind the curtain) for your software to use internally so that a nice pdf file is created.
If you already have LaTeX installed or if you have already followed the instructions in the slides and installed all recommended packages, you should be fine. If not, run the following in your R console:
install.packages('tinytex')
After that, run
tinytex::install_tinytex()
The above steps might take a while. It took 15 minutes on my computer. Do not get disheartened; get a snack or do “theoretical” problems while you wait.
Once all is installed, you can check if everything is in order by asking your computer. Run
tinytex:::is_tinytex()
If you get TRUE, all is well!
All submissions of computational work have to be produced using an R Notebook, i.e., via an Rmd file. This does not mean that you are supposed to submit and Rmd file, this means that you use an Rmd file to create a pdf file. The pdf file is what you upload as your final submission.
One of the learning objectives of this course is for you to be able to conduct elementary statistical analyses and present the results. Producing your final submission using an R-notebook is probably the most painless way.
As we discussed in class, an R notebook is nothing other than a specially formatted text file which contains chunks or R code mixed with regular text. The point is that it can be transformed into a good looking pdf (or html) file by a press of a button. When you open an R notebook in RStudio, you will be able to write your problem solutions, perform R computations and even plot graphs in one fell swoop. What is more important, the results of the computations and the graphs you produce will automatically become a part of the output document. You have already seen the effect in class demonstrations.
The following notation
```{r}
```
marks a code chunk. Btw, the apostrophe-like symbols above are backticks - they live on the key below the escape key. You should not worry about counting how many there are or how to type them in - pressing Cmd+Option+I (on a Mac) or Ctrl+Alt+I (on Windows or Linux) will insert the whole thing for you.
To see all available keyboard shortcuts available on your platform, press Option+Shift+K (on a Mac) or Alt+Shift+K (on Windows or Linux) in RStudio.
Anything within the code chunk is treated as R code to be evaluated on the spot. The result of the evaluation will automatically become a part of the notebook. The same is true for graphs - you don’t have to produce separate files; they will be automatically integrated into the output document. For those of you familiar with the Python ecosystem, Rmd documents are R’s version of Jupyter notebooks.
For a full workflow overview, you can consult the RMarkdown cheatsheet.
There is a sample homework Rmd file that you can use as a template. Click on the homework template.
Make the following changes:
Do not touch the next R chunk, unless you are absolutely confident that you know what you’re doing.
The remainder of the template is pretty self-explanatory. You can insert your solutions to the problems in order. Note that:
You are now ready to create your pdf file. Simply do Ctrl+Shift+K (on Windows or Linux) or Cmd+Shift+K (on a Mac). Your final pdf file should simply appear in your favorite viewer. Now, you can upload it to Canvas.
Of course, you are going to cycle through your previous two steps multiple times. Each time you write in some new code or an explanation, create the pdf to see how it looks.