class: center, middle, title-slide # Writing reproducible documents ### Olivier Gimenez ### last updated: 2021-02-26 --- ## Context We will use the awesome `palmerpenguins` dataset 🐧, an alternative to Fisher's `iris` dataset, to explore and visualize data. These data have been collected and shared by [Dr. Kristen Gorman](https://www.uaf.edu/cfos/people/faculty/detail/kristen-gorman.php) and [Palmer Station, Antarctica LTER](https://pal.lternet.edu/). The package was built by Drs Allison Horst and Alison Hill, check out the [official website](https://allisonhorst.github.io/palmerpenguins/). The package `palmerpenguins` has two datasets. ```r library(palmerpenguins) data(package = 'palmerpenguins') ``` --- The dataset `penguins` is a simplified version of the raw data; see `?penguins` for more info: .tiny-font[ ```r head(penguins) ``` ``` ## # A tibble: 6 x 8 ## species island bill_length_mm bill_depth_mm flipper_length_… body_mass_g sex ## <fct> <fct> <dbl> <dbl> <int> <int> <fct> ## 1 Adelie Torge… 39.1 18.7 181 3750 male ## 2 Adelie Torge… 39.5 17.4 186 3800 fema… ## 3 Adelie Torge… 40.3 18 195 3250 fema… ## 4 Adelie Torge… NA NA NA NA <NA> ## 5 Adelie Torge… 36.7 19.3 193 3450 fema… ## 6 Adelie Torge… 39.3 20.6 190 3650 male ## # … with 1 more variable: year <int> ``` ] --- The other dataset `penguins_raw` has the raw data; see `?penguins_raw` for more info: .tiny-font[ ```r head(penguins_raw) ``` ``` ## # A tibble: 6 x 17 ## studyName `Sample Number` Species Region Island Stage `Individual ID` ## <chr> <dbl> <chr> <chr> <chr> <chr> <chr> ## 1 PAL0708 1 Adelie Pengu… Anvers Torger… Adult,… N1A1 ## 2 PAL0708 2 Adelie Pengu… Anvers Torger… Adult,… N1A2 ## 3 PAL0708 3 Adelie Pengu… Anvers Torger… Adult,… N2A1 ## 4 PAL0708 4 Adelie Pengu… Anvers Torger… Adult,… N2A2 ## 5 PAL0708 5 Adelie Pengu… Anvers Torger… Adult,… N3A1 ## 6 PAL0708 6 Adelie Pengu… Anvers Torger… Adult,… N3A2 ## # … with 10 more variables: Clutch Completion <chr>, Date Egg <date>, ## # Culmen Length (mm) <dbl>, Culmen Depth (mm) <dbl>, ## # Flipper Length (mm) <dbl>, Body Mass (g) <dbl>, Sex <chr>, ## # Delta 15 N (o/oo) <dbl>, Delta 13 C (o/oo) <dbl>, Comments <chr> ``` ] For this exercise, we're gonna use the `penguins` dataset. --- ## Question 1 * Create a new R Markdown document, name it and save it. * Delete everything after line 12. * Add a new section title, simple text and text in bold font. * Compile ("Knit"). --- ## Question 2 * Add a chunk in which you load the `palmerpenguins`. The corresponding line of code should be hidden in the output. * Load also the `tidyverse` suite of packages. * Modify the defaults to suppress all messages. --- ## Question 3 * Add another chunk in which you build a table with the 10 first rows of the dataset. --- ## Question 4 * In a new section, display how many individuals, penguins species and islands we have in the dataset. This info should appear directly in the text, you might want to use inline code 😄. * Calculate the mean of the (numeric) traits measured on the penguins. --- ## Question 5 * In another section, entitled 'Graphical exploration', build a figure with 3 superimposed histograms, each one corresponding to the body mass of a species. --- ## Question 6 * Install package `citr` to manage citations following the guidelines [here](https://github.com/crsh/citr). If everything goes well, you should see it in the pulldown menu `Addins` 💪. * Pick a recent publication from the researcher who shared the data, Dr Kristen Gorman. Import this publication in your favorite references manager (we use Zotero, no hard feeling), and create a bibtex reference that you will add to to the file `mabiblio.bib`. * Add `bibliography: mabiblio.bib` at the beginning of your R Markdown document (YAML). * Cite the reference iin the text using `Insert citations` in the pull-down menu `Addins`. * Compile. --- ## Question 7 * Change the default citation format (Chicago style) into the The American Naturalist format. It can be found here <https://www.zotero.org/styles>. To do so, add `csl: the-american-naturalist.csl` in the YAML. --- ## Question 8 * Build your report in html, pdf and docx format. 🎉