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 has a deep integration 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.
Task Windows & Linux macOS
Insert R chunk Ctrl+Alt+I Command+Option+I
Preview HTML Ctrl+Shift+K Command+Shift+K
Knitr document (knitr) Ctrl+Shift+K Command+Shift+K
Compile Notebook Ctrl+Shift+K Command+Shift+K
Compile PDF Ctrl+Shift+K Command+Shift+K
Run all chunks above Ctrl+Alt+P Command+Option+P
Run current chunk Ctrl+Alt+C Command+Option+C
Run current chunk Ctrl+Shift+Enter Command+Shift+Enter
Run next chunk Ctrl+Alt+N Command+Option+N
Run all chunks Ctrl+Alt+R Command+Option+R
Go to next chunk/title Ctrl+PgDown Command+PgDown
Go to previous chunk/title Ctrl+PgUp Command+PgUp
Show/hide document outline Ctrl+Shift+O Command+Shift+O
Build book, website, … Ctrl+Shift+B Command+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 dropdown menu “Restart R and Run All Chunks” behind the “Run” button on the toolbar.