Chapter 2 A new chapter

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

To see the rendered version of this chapter and the rest of the template, see here: https://jhudatascience.org/OTTR_Template/.

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 Topic of Section

You can write all your text in sections like this, using ## to indicate a new header. you can use additional pound symbols to create lower levels of headers.

See here for additional general information about how you can format text within R Markdown files. In addition, see here for more in depth and advanced options.

2.3.1 Subtopic

Here’s a subheading (using three pound symbols) and some text in this subsection!

2.4 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.5 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.6 Video examples

You may also want to embed videos in your course. If alternatively, you just want to include a link you can do so like this:

Check out this link to a video using markdown syntax.

2.6.1 Using knitr

To embed videos in your course, you can use knitr::include_url() like this: Note that you should use 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.

2.6.2 Using HTML

2.6.3 Using knitr

2.6.4 Using HTML

2.7 Website Examples

Yet again you can use a link to a website like so:

A Website

You might want to have users open a website in a new tab by default, especially if they need to reference both the course and a resource at once.

A Website

Or, you can embed some websites.

2.7.1 Using knitr

This works:

2.7.2 Using HTML

If you’d like the URL to show up in a new tab you can do this:

<a href="https://www.linkedin.com" target="_blank">LinkedIn</a>

2.8 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.9 Stylized boxes

Occasionally, you might find it useful to emphasize a particular piece of information. To help you do so, we have provided css code and images (no need for you to worry about that!) to create the following stylized boxes.

You can use these boxes in your course with either of two options: using HTML code or Pandoc syntax.

2.9.1 Using rmarkdown container syntax

The rmarkdown package allows for a different syntax to be converted to the HTML that you just saw and also allows for conversion to LaTeX. See the Bookdown documentation for more information (Xie, Dervieux, and Riederer 2020). Note that Bookdown uses Pandoc.

::: {.notice}
Note using rmarkdown syntax.

:::

Note using rmarkdown syntax.

As an example you might do something like this:

Please click on the subsection headers in the left hand navigation bar (e.g., 2.1, 4.3) a second time to expand the table of contents and enable the scroll_highlight feature (see more)

2.9.2 Using HTML

To add a warning box like the following use:

<div class = "notice">
Followed by the text you want inside
</div>

This will create the following:

Followed by the text you want inside

Here is a <div class = "warning"> box:

Note text

Here is a <div class = "github"> box:

GitHub text

Here is a <div class = "dictionary"> box:

dictionary text

Here is a <div class = "reflection"> box:

reflection text

Here is a <div class = "wip"> box:

Work in Progress text

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.
Xie, Yihui, Christophe Dervieux, and Emily Riederer. 2020. R Markdown Cookbook. Boca Raton, Florida: Chapman; Hall/CRC. https://bookdown.org/yihui/rmarkdown-cookbook.