Post With Code

news
code
analysis
Author

Harlow Malloc

Published

August 10, 2022

library(tidyverse)
── Attaching packages ─────────────────────────────────────── tidyverse 1.3.2 ──
✔ ggplot2 3.3.6     ✔ purrr   0.3.4
✔ tibble  3.1.8     ✔ dplyr   1.0.9
✔ tidyr   1.2.0     ✔ stringr 1.4.0
✔ readr   2.1.2     ✔ forcats 0.5.1
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag()    masks stats::lag()
library(palmerpenguins)

The dataset contains 344 penguin size measurements from Adelie, Gentoo, Chinstrap species across Torgersen, Biscoe, Dream islands..

What about formatting?

pen_summary <- penguins |> 
  group_by(species) |> 
  summarize(avg_mass = mean(body_mass_g, na.rm = TRUE))

The average body mass by species is 3700.6622517, 3733.0882353, 5076.0162602.

We can do better!

body_mass <- scales::label_number(big.mark = ",", accuracy = 0.1, suffix = "g")(pull(pen_summary, avg_mass))

body_mass
[1] "3,700.7g" "3,733.1g" "5,076.0g"

The average body mass by species is 3,700.7g, 3,733.1g, 5,076.0g.

We can still do better!

mass_reporter <- glue::glue_collapse(body_mass, sep = ", ", last = ", and ")

The average body mass by species is 3,700.7g, 3,733.1g, and 5,076.0g.

Reporting with lists

Credit to TJ Mahr

knitted <- list(
  when = format(Sys.Date()),
  with = system("quarto --version", intern = TRUE)
)

Reported prepared on 2022-08-11 with quarto version 1.0.38.