library(here)
coviddat <- read.csv(here("Data", "minnesota-history.csv"))Reproducible Reports in R
Exercise 1
Create a project in Rstudio associated with this course/book using the directions at this link.
Create a subdirectory to hold your scripts as you work through the book. You may label this anything you want, but I would suggest avoiding spaces or special characters in the name.
Copy (don’t cut and paste)
L00_ReproducibleReportsExercise0.1.qmdfrom theCodeTemplatessubdirectory of theStats4EcologistsFilesGitHub repository contained here to the directory you created in step 1.Use the
herepackage (Müller 2020) and code in the code template to read in theminnesota-history.csvdata set in theFW8051Datasubfolder. This data set contains COVID-19 tracking data from Minnesota. I downloaded these data from this site. You can find metadata here.
Using the here package (or, alternatively, a relative path), will make it easy to someday transfer your code to another computer or to share (say with a friend) and still have the code work right out of the box. This will not likely be the case if you use something like:
coviddat <- read.csv("c:\\My Documents\\MyStatsClass\\minnesota-history.csv")- Add R code necessary to plot the number of deaths over time. This will require that you grapple with a date variable in R. Some resources that may help if you struggle to figure out how to work with dates in R include:
- https://www.statmethods.net/input/dates.html
- https://r4ds.had.co.nz/dates-and-times.html
- your colleagues in this class!
- Create a reproducible pdf (or html) document with code and output. This can be accomplished by clicking on the “Render” button in Rstudio.
Exercise 2
For this exercise, we will create a reproducible document using the same steps as in Exercise 0.1. However, we will work with an R script rather than a .qmd file.
Follow steps 1-2 of
L00_ReproducibleReportsExercise0.1.qmd.Copy (don’t cut and paste)
L00_ReproducibleReportsExercise0.1.Rfrom theCodeTemplatessubdirectory of theStats4EcologistsFilesGitHub repository contained here to the directory you created in step 1.
Note that:
- the YAML header and any text from your .Rmd file is included with a
#'in front of it.
- any code chunk options will be included with a
#+.
- Use the
herepackage (Müller 2020) and code in the code template to read in theminnesota-history.csvdata set in theFW8051Datasubfolder. This data set contains COVID-19 tracking data from Minnesota. I downloaded these data from this site. You can find metadata here.
library(here)
coviddat <- read.csv(here("Data", "minnesota-history.csv"))Using the here package (or, alternatively, a relative path), will make it easy to someday transfer your code to another computer or to share (say with a friend) and still have the code work right out of the box. This will not likely be the case if you use something like:
coviddat <- read.csv("c:\\My Documents\\MyStatsClass\\minnesota-history.csv")- Add R code necessary to plot the number of deaths over time. This will require that you grapple with a date-time variable in R. Some resources that may help if you struggle to figure out how to work with dates in R include:
- https://www.statmethods.net/input/dates.html
- https://r4ds.had.co.nz/dates-and-times.html
- your colleagues in this class!
- You can then create your reproducible report by clicking File > Compile Report (and then selecting pdf, html, or MS Word).
Exercise 3
- Create a report containing the following:
- Bold and italicized text
- The symbol: \(\beta\)
- The equation: \(\pi r^2 = 12\)
- A link to a website
- Some simple R code and a figure
If you get stuck, consult the following resources:
- RStudio’s tutorial: https://rmarkdown.rstudio.com
- The cheat sheet: https://www.rstudio.com/wp-content/uploads/2015/02/rmarkdown-cheatsheet.pdf
- The knitR book: https://yihui.name/knitr/
- The R Markdown cookbookhttps://bookdown.org/yihui/rmarkdown-cookbook/