Chapter 2 A new chapter

*If you haven’t yet read the getting started Wiki pages; start there

Every chapter needs to start out with this chunk of code:

2.1 Learning Objectives

*Every chapter also needs Learning objectives that will look like this:

This chapter will cover:

2.2 Libraries

For this chapter, we’ll need the following packages attached:

*Remember to add any additional packages you need to your course’s own docker image.

library(magrittr)

2.3 Subtopic

Here’s a subheading and some text in this subsection!

2.3.1 Code examples

You can demonstrate code like this:

output_dir <- file.path("resources", "code_output")
if (!dir.exists(output_dir)) {
  dir.create(output_dir)
}

And make plots too:

hist_plot <- hist(iris$Sepal.Length)

You can also save these plots to file:

png(file.path(output_dir, "test_plot.png"))
hist_plot
## $breaks
## [1] 4.0 4.5 5.0 5.5 6.0 6.5 7.0 7.5 8.0
## 
## $counts
## [1]  5 27 27 30 31 18  6  6
## 
## $density
## [1] 0.06666667 0.36000000 0.36000000 0.40000000 0.41333333 0.24000000 0.08000000
## [8] 0.08000000
## 
## $mids
## [1] 4.25 4.75 5.25 5.75 6.25 6.75 7.25 7.75
## 
## $xname
## [1] "iris$Sepal.Length"
## 
## $equidist
## [1] TRUE
## 
## attr(,"class")
## [1] "histogram"
dev.off()
## png 
##   2

2.3.2 Image example

How to include a Google slide. It’s simplest to use the ottrpal package:

Major point!! example image

But if you have the slide or some other image locally downloaded you can also use html like this:

Major point!! example image

2.3.3 Video examples

To show videos in your course, you can use markdown syntax like this:

A video we want to show

Alternatively, you can use knitr::include_url() like this: Note that we are using echo=FALSE in the code chunk because we don’t want the code part of this to show up. If you are unfamiliar with how R Markdown code chunks work, read this.

OR this works:

2.3.6 Citation examples

We can put citations at the end of a sentence like this (Allaire et al. 2021). Or multiple citations Xie, Allaire, and Grolemund (2018).

but they need a ; separator (Allaire et al. 2021; Xie, Allaire, and Grolemund 2018).

In text, we can put citations like this Allaire et al. (2021).

2.3.7 Callout boxes

There are some preset callout boxes available, which can be used like so:

notice:

Here’s something interesting.

warning:

Look out!

dictionary:

Here’s a definition.

reflection:

Consider this!

github:

Here’s how you use GitHub.

wip:

This section is a Work in Progress.

References

Allaire, JJ, Yihui Xie, Jonathan McPherson, Javier Luraschi, Kevin Ushey, Aron Atkins, Hadley Wickham, Joe Cheng, Winston Chang, and Richard Iannone. 2021. Rmarkdown: Dynamic Documents for r. https://github.com/rstudio/rmarkdown.
Xie, Yihui, J. J. Allaire, and Garrett Grolemund. 2018. R Markdown: The Definitive Guide. Boca Raton, Florida: Chapman; Hall/CRC. https://bookdown.org/yihui/rmarkdown.