Chapter 1 Introduction

1.1 How to contribute

(Steps 1. to 3. only need to be done once - to set-up.)

  1. Connect your RStudio and GitHub using these instructions, only up to “Create new project” is necessary here (the repository/project already exists): https://www.datasurg.net/2015/07/13/rstudio-and-github/

  2. Get your GitHub account added to the surgicalinformatics organisation on GitHub (ask Riinu/Ewen): https://github.com/SurgicalInformatics

  3. In RStudio: New Project - Version Control - git, then copy the URL: https://github.com/SurgicalInformatics/cookbook

  4. Add your thing by editing the appropriate .Rmd file - there’s one for each chapter. In the Build pane (next to Environment) click on More - Clean All (if you don’t do this you may be able to compile the book with code that won’t work at a subsequent clean build which can be trickier to debug). Use the Build tab to Build your changes into a book.

  5. If anyone has pushed since you cloned/last pulled (hopefully they’ve not been working on the exact same chapter): Make sure you click on More - Clean All (as above). Then Pull from the Git tab. This only cleans the output files - html and PDF, it will not touch the changes you’ve made in the .Rmd file.

  6. Then Build Book again - this will include the new changes you pulled as well as your changes.

  7. Git tab - commit everything, Push quickly before anyone else does or you’ll have to go back to step 5. You can check for new pushed commits here: https://github.com/SurgicalInformatics/cookbook/commits/master Alternatively there’s no harm in clicking the Pull button again - it should then say “Already up-to-date”.

Pro tip: instead of clicking on every single file in the Git tab, go to the terminal, cd cookbook to go to the project folder if still home, and do git add . which is the same thing. Still need to Commit though!

8. Have fun!

1.2 Indexing

1.2.1 Index

Bold index headings:
\index{linear regression@\textbf{linear regression}} (ticks in .Rmd file are excluded when actually using)

Sub-entries of bold headings:
\index{linear regression@\textbf{linear regression}!diagnostics}

Stand-alone entries:
\index{linear regression}

1.2.2 Chapter and section references

You can label chapter and section titles using {#label} after them, e.g., we can reference Chapter \@ref(intro) (ticks in .Rmd are excluded when actually using). If you do not manually label them, there will be automatic labels anyway, e.g., Chapter \@ref(methods).

1.2.3 Figure and table references

Figures and tables with captions will be placed in figure and table environments, respectively.

par(mar = c(4, 4, .1, .1))
plot(pressure, type = 'b', pch = 19)
Here is a nice figure!

Figure 1.1: Here is a nice figure!

Reference a figure by its code chunk label with the fig: prefix, e.g., see Figure \@ref(fig:nice-fig). Similarly, you can reference tables generated from knitr::kable(), e.g., see Table \@ref(tab:nice-tab).

knitr::kable(
  head(iris, 20), caption = 'Here is a nice table!',
  booktabs = TRUE
)
Table 1.1: Here is a nice table!
Sepal.Length Sepal.Width Petal.Length Petal.Width Species
5.1 3.5 1.4 0.2 setosa
4.9 3.0 1.4 0.2 setosa
4.7 3.2 1.3 0.2 setosa
4.6 3.1 1.5 0.2 setosa
5.0 3.6 1.4 0.2 setosa
5.4 3.9 1.7 0.4 setosa
4.6 3.4 1.4 0.3 setosa
5.0 3.4 1.5 0.2 setosa
4.4 2.9 1.4 0.2 setosa
4.9 3.1 1.5 0.1 setosa
5.4 3.7 1.5 0.2 setosa
4.8 3.4 1.6 0.2 setosa
4.8 3.0 1.4 0.1 setosa
4.3 3.0 1.1 0.1 setosa
5.8 4.0 1.2 0.2 setosa
5.7 4.4 1.5 0.4 setosa
5.4 3.9 1.3 0.4 setosa
5.1 3.5 1.4 0.3 setosa
5.7 3.8 1.7 0.3 setosa
5.1 3.8 1.5 0.3 setosa

1.2.4 Citations

You can write citations, too. For example, we are using the bookdown package (Xie 2023) in this sample book, which was built on top of R Markdown and knitr (Xie 2015).

References

Xie, Yihui. 2015. Dynamic Documents with R and Knitr. 2nd ed. Boca Raton, Florida: Chapman; Hall/CRC. http://yihui.name/knitr/.
———. 2023. Bookdown: Authoring Books and Technical Documents with r Markdown. https://github.com/rstudio/bookdown.