Files and Folders

It is essential that you name your folders and files exactly as specified. We run checks like

cd HW2
Rscript -e 'rmarkdown::render("hw2.Rmd")'

from the top of a clone of your repository. If the folders and files are not named exactly as specified these checks will fail and your work will not be graded.

Rmarkdown Usage and Coding Style

Make sure you are using Rmarkdown properly, with explanatory texts surrounding short code chunks. In particular you should not have just one big code chunk.

Your rendered HTML page should be a report with text supporting numerical and graphical results. Code only needs to be visible if you are explaining how to do something (which is a goal of the class notes).

Your Rmarkdown code and your R code should be readable, and the R code should follow the coding standards. This makes maintaining your code and document easier.

Name and Date

Make sure your Rmarkdown file header contains a name: field with your name. A date: field with an appropriate date is also helpful.

Your header should look something like this:

---
title: "HW2"
output: html_document
name: "Your  Name"
date: "February 1, 2022"
---

You can also use one of these as the date line to produce the current date when the document is knit:

date: "`r Sys.Date()`"
date: "`r format(Sys.Date(), '%B %e, %Y')`"

Reproducibility

Make sure your .Rmd file will knit without errors.

Handling Data Files

If your Rmarkdown document makes use of an external data file you need to make sure it can be accessed when someone you give your repository to renders your file. There are several options:

Relying on retrieving a file from the network means it may change or be removed. In some cases this will be what you want, in others maybe not.

Avoiding Messages and Warnings in Output

Some packages produce messages when they are loaded and some computations produce messages or warnings. In a final report you usually do not want these to be visible. You can suppress messages, like the ones produces when loading the tidyverse by adding the chunk option message = FALSE. Warnings can also be suppressed with the chunk option warning = FALSE, but it is usually better make sure you understand where the warnings are coming from and modify your code to avoid them (e.g. by adding na.rm = TRUE to some calls).

1. Average Infant Mortality Rate Continent in 2015

The following table shows the average infant mortality rate, in deaths per 1000 live births, for 2015 across countries in five continents as defined in the gapminder data set from the dslabs package.

Continent Infant Mortality
Africa 48.0
Americas 15.6
Asia 18.6
Europe 4.5
Oceania 22.0

Infant mortality for Africa is still quite a bit higher than for the other continents.

2. Average Infant Mortality Rate Over the Years

This graph shows average infant mortality rate over the years for the five continents defined in the gapminder data set from the dslabs package.

All continents show a decrease in infant mortality over time. The curve for Africa is noticeably higher than the curves for the other continents. The bump for 1990-2000 in the Africa curve reflects famine events and conflicts in Africa during these years.

3. Mauna Loa Atmospheric CO\(_2\) Concentration

This plot shows the yearly average CO\(_2\) concentration measured at the Mauna Loa Observatory in Hawaii. Measurements are in parts per million.

CO\(_2\) levels have been rising consistently over the years, with the rate of increase appearing to rise slowly as well.

LS0tCnRpdGxlOiAiQXNzaWdubWVudCAyIE5vdGVzIgpvdXRwdXQ6CiAgaHRtbF9kb2N1bWVudDoKICAgIHRvYzogeWVzCiAgICBjb2RlX2Rvd25sb2FkOiB0cnVlCi0tLQoJICAKYGBge3IgZ2xvYmFsX29wdGlvbnMsIGluY2x1ZGUgPSBGQUxTRX0Ka25pdHI6Om9wdHNfY2h1bmskc2V0KGNvbGxhcHNlID0gVFJVRSkKYGBgCgojIyBGaWxlcyBhbmQgRm9sZGVycwoKSXQgaXMgZXNzZW50aWFsIHRoYXQgeW91IG5hbWUgeW91ciBmb2xkZXJzIGFuZCBmaWxlcyBfZXhhY3RseV8gYXMKc3BlY2lmaWVkLiBXZSBydW4gY2hlY2tzIGxpa2UKYGBgc2hlbGwKY2QgSFcyClJzY3JpcHQgLWUgJ3JtYXJrZG93bjo6cmVuZGVyKCJodzIuUm1kIiknCmBgYApmcm9tIHRoZSB0b3Agb2YgYSBjbG9uZSBvZiB5b3VyIHJlcG9zaXRvcnkuIElmIHRoZSBmb2xkZXJzCmFuZCBmaWxlcyBhcmUgbm90IG5hbWVkIF9leGFjdGx5XyBhcyBzcGVjaWZpZWQgdGhlc2UgY2hlY2tzIHdpbGwgZmFpbAphbmQgeW91ciB3b3JrIHdpbGwgbm90IGJlIGdyYWRlZC4KCgojIyBSbWFya2Rvd24gVXNhZ2UgYW5kIENvZGluZyBTdHlsZQoKTWFrZSBzdXJlIHlvdSBhcmUgdXNpbmcgUm1hcmtkb3duIHByb3Blcmx5LCB3aXRoIGV4cGxhbmF0b3J5IHRleHRzCnN1cnJvdW5kaW5nIHNob3J0IGNvZGUgY2h1bmtzLiBJbiBwYXJ0aWN1bGFyIHl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