class: right, middle, title-slide # Writing a report with R Markdown ## Practical --- ## Context Let's apply what we have learnt in the course on [Writing dynamic and reproducible documents - An introduction to R Markdown](https://oliviergimenez.github.io/intro_rmarkdown/#1). 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: ```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: ```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⦠Anvers Torge⦠Adul⦠N1A1 ## 2 PAL0708 2 Adelie⦠Anvers Torge⦠Adul⦠N1A2 ## 3 PAL0708 3 Adelie⦠Anvers Torge⦠Adul⦠N2A1 ## 4 PAL0708 4 Adelie⦠Anvers Torge⦠Adul⦠N2A2 ## 5 PAL0708 5 Adelie⦠Anvers Torge⦠Adul⦠N3A1 ## 6 PAL0708 6 Adelie⦠Anvers Torge⦠Adul⦠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. --- ## Questions **1)** Install the package `palmerpenguins`. **2)** 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"). **3)** 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. **4)** Add another chunk in which you build a table with the 10 first rows of the dataset. **5)** 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. --- **6)** In another section, entitled 'Graphical exploration', build a figure with 3 superimposed histograms, each one corresponding to the body mass of a species. **7)** Instal package `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. **8)** 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 soo, add `csl: the-american-naturalist.csl` in the YAML. **9)** Build your report in html, pdf and docx format. š