Here is this month’s collection of RStudio Tips and Tricks. Thank you to those who responded to last month’s post; many of your tips are included below! Be sure to subscribe to @rstudiotips on Twitter for more.
This month’s tips fall into two categories: Keyboard Shortcuts and Easier R Markdown.
The RStudio IDE is built upon “hooks”. Hooks are actions that the IDE can take. For instance, there is a hook to create a new file. Most users interact with hooks with point-and-click interactions. (
RStudio toolbar -> new file or
File -> New File). But, there is an alternative! All of these hooks have been surfaced to end users and can be bound to a keyboard shortcut. (Some of these actions are “secret” - they aren’t exposed through point-and-click options.)
Custom Keyboard Shortcuts
To view the complete list of actions, the current keybindings, and to customize keybindings, go to:
Tools -> Modify Keyboard Shortcuts.
Code Chunk Navigation
Define shortcuts for code chunk navigation using the previous tip. For example,
Alt+Cmd+Down for Next Chunk and
Alt+Cmd+Up for Previous Chunk.
Alt at the same time as pressing
-). This adds the assignment operator and spacing.
Cmd+Shift+m (for Mac) or
Ctrl+Shift+m (for Windows). This adds the pipe operator
%>% and spacing.
Easier R Markdown
R Markdown Options
R Markdown output formats include arguments specified in the YAML header. Don’t worry about remembering all of the key-value pairs; in RStudio, you can access and change the most common through a user-interface.
Use the built-in spell checker when writing a R Markdown document. (Code chunks are automatically ignored.)
SQL Code Chunks
Execute SQL queries against database connections directly in R Markdown chunks.
R Markdown Websites
Are you building a website with R Markdown? Any RStudio project with an R Markdown website will include a Build Website option in the build pane.
What’s your favorite RStudio Tip?