17.1 Use RStudio keyboard shortcuts

The R Markdown format can be used with any editor of your choice, as long as R, the rmarkdown package, and Pandoc are installed. However, RStudio is deeply integrated with R Markdown, so you can work with R Markdown smoothly.

Like any IDE (Integrated Development Environment), RStudio has keyboard shortcuts. A full list can be found under the menu Tools -> Keyboard Shortcuts Help. Some of the most useful shortcuts related to R Markdown are summarized in Table 17.1.

TABLE 17.1: RStudio keyboard shortcuts related to R Markdown.
TaskWindows & LinuxmacOS
Insert R chunkCtrl+Alt+ICommand+Option+I
Preview HTMLCtrl+Shift+KCommand+Shift+K
Knitr document (knitr)Ctrl+Shift+KCommand+Shift+K
Compile NotebookCtrl+Shift+KCommand+Shift+K
Compile PDFCtrl+Shift+KCommand+Shift+K
Run all chunks aboveCtrl+Alt+PCommand+Option+P
Run current chunkCtrl+Alt+CCommand+Option+C
Run current chunkCtrl+Shift+EnterCommand+Shift+Enter
Run next chunkCtrl+Alt+NCommand+Option+N
Run all chunksCtrl+Alt+RCommand+Option+R
Go to next chunk/titleCtrl+PgDownCommand+PgDown
Go to previous chunk/titleCtrl+PgUpCommand+PgUp
Show/hide document outlineCtrl+Shift+OCommand+Shift+O
Build book, website, …Ctrl+Shift+BCommand+Shift+B

Additionally, you can press F7 to spell-check your document. You can also restart the R session by Ctrl + Alt + F10 (or Command + Option + F10 on macOS). Restarting regularly is helpful for reproducibility, because results are more likely to be reproducible if they are computed from a new R session. This can also be done through the drop-down menu Restart R and Run All Chunks behind the Run button on the toolbar.