1  Preface

1.1 R code blocks

Throughout this book you will see blocks with R code followed by its output, if the given code produced any. The code (or input) is decorated with a light blue border on the left to separate it from its output, like in the following example:

x <- rnorm(200)
x[1:20]
 [1] -0.32412762 -0.34315695  0.08411278  0.51630237  0.83234474  0.70424472
 [7]  0.50710695  0.01085382  0.05436562  1.48439496  0.80626144 -1.07497745
[13] -0.71190409 -1.00119292  1.02868890 -2.16336942 -0.37621862 -1.10787559
[19] -1.59520597 -1.84417230

If you mouse over the input code box, a clickable “Copy to clipboard” button appears on the top right of the box allowing you to copy & paste into an R console or file.

Notice that R adds numbers in brackets in the beginning of each row. This happens when R prints the contents of a vector. The number is the integer index of the first element in that row. Therefore, the first one is always [1] and the number of the subsequent rows depends on how many elements fit in each line. If the output is a single element, it will still have [1] in front of it.

If we enclose the assignment operation of a variable in parentheses, the object is printed to the console. Therefore, this:

(y <- 4)
[1] 4

is equivalent to this:

y <- 4
y
[1] 4

1.2 WebR executable code blocks

WebR is a new technology that allows running R in the browser. As the content of the book is being updated and extended, you will see executable blocks like the one below. Note how you can edit the code and hit Run or use the keyboard shortcut Shift + Enter to execute.

1.3 Fonts

This site uses Fira Code to display source code. Like a number of other font families, it supports a number character ligatures that make code look prettier / easier to read. Note that even though ligations make some symbol combinations look like a single symbol, they are still separate characters.
For example, the assignment operator, <-, is still written using the characters < and -.

Figure 1.1: Ligated versions of some common character combinations as they should appear in this site

1.4 Themes

The light/dark mode switch is located in the top left of the page. Note that most figures will appear with inverted colors when the dark theme is selected, i.e. the true colors are displayed with the light theme only.

1.5 Made with Quarto

This book was created using Quarto. The first version of the book had been built using bookdown.