This is a book created from markdown and executable code.

See Knuth (1984) for additional discussion of literate programming.

1.1 Key content

This is an example of a ‘folded’ caution callout that can be expanded by the user. You can use collapse="true" to collapse it by default or collapse="false" to make a collapsible callout that is expanded by default.

1.2 Create an object to see if it crosses chapters

Code
xtest <- 24

1.3 Example of inline code

Before we defined the object xtest (see previous code block). You can also use integrate short code blocks into the narrative using “inline code” … Type 24 and the value of the object xtest shows up in your code, here 24.

1.4 Showing some material

What if I want the code to be folded but not to spit results and side effects onto the screen?

Code
3+5

a <- "happiness"

happiness

Did it display the sum? Was the object defined?

1.5 Labeling/captioning chunks

Wait, why do we just have ‘code’ labeling the chunks when you fold them. It would be much more useful to have a descriptive label you can see in the html. We can do this in each chunk with #| code-summary: "blah blah", as below

Note: the chunk options content itself is not shown. Below, we have:


#| label: car-talk
#| code-summary: "Car talk stuff"

head(mtcars)
Car talk stuff
head(mtcars)
                   mpg cyl disp  hp drat    wt  qsec vs am gear carb
Mazda RX4         21.0   6  160 110 3.90 2.620 16.46  0  1    4    4
Mazda RX4 Wag     21.0   6  160 110 3.90 2.875 17.02  0  1    4    4
Datsun 710        22.8   4  108  93 3.85 2.320 18.61  1  1    4    1
Hornet 4 Drive    21.4   6  258 110 3.08 3.215 19.44  1  0    3    1
Hornet Sportabout 18.7   8  360 175 3.15 3.440 17.02  0  0    3    2
Valiant           18.1   6  225 105 2.76 3.460 20.22  1  0    3    1