Advanced R Markdown

Author

Jeffrey R. Stevens

Published

May 5, 2025

  1. Create a new R Markdown file and save it (or download this file by changing the extension in your browser from html to Rmd and removing all # >). Edit the YAML header to make the output bookdown::html_document2. Add a code chunk labeled setup that loads tidyverse, knitr, and bookdown. Set the code chunk option collapse to TRUE.
# >
  1. Add a code chunk that creates and prints an object called mtcars10 that is the first 10 rows of the mtcars dataset.
# >
  1. Pass mtcars10 to the kable() function to properly format a table in the R Markdown document.
# >
  1. Repeat #2 but edit the code chunk options so that the R code does not show up in the document but the table does.
# >
  1. Repeat #2 but edit the code chunk options so that neither the R code nor table show up in the document.
# >
  1. Repeat #2 but edit the code chunk options so that the R code is not run but the code does show up in the document.
# >
  1. In a code chunk, plot a histogram of fuel efficiency from the full mtcars dataset, but edit the code chunk so that the message about bin widths does not show up in the document.
# >
  1. Repeat #6 but give the figure the label mpg-hist and the caption “Fuel efficiency histogram” and set the figure width and height to 5.
# >
  1. Repeat #7 but change the label to mpg-hist2 (you can’t have two chunks with same label) and set the output height and width to 400. Also, write some text outside the code chunk that cross references both figures.
# >
  1. Add a code chunk labeled dogs that inserts this image into the document: https://pbs.twimg.com/media/Fr7AiG_WcBI3Zxh?format=jpg&name=4096x4096 without showing the code. Include alt text describing the image to a reader with visual impairment.
# >