RStudio

Keyboard Shortcuts

Mac Users

In place of Ctrl in the keyboard shortcuts below, use Cmd.

RStudio Tips

RStudio Tip on X on how to use RStudio IDE effectively.

Below is a set of helpful keyboard shortcut. The full list can be reached by clicking Tools -> Keyboard Shortcut Help (Alt+Shift+K) -> See All Shortcuts

  • Ctrl+Enter: execute the code statement at which cursor is standing and move the cursor to the beginning of the next statement
  • Ctrl+Shift+S: execute the whole R script
  • Ctrl+Alt+I: insert new code chunk
  • Ctrl+Shift+C: comment/un-comment
  • Alt-⬆️: move line up
  • Alt-⬇️️: move line down
  • Ctrl+D: delete line
  • Ctrl+Shift+A: format code
  • Ctrl+M: add pipe |> operator–to change from %>%, go to Tools -> Global Options… -> Code section -> Editing tab -> check Use native pipe operator, |> (requires R 4.1+)
  • Ctrl++: increase font size of all windows
  • Ctrl+-: decrease font size of all windows
  • Alt+- : insert assignment <-. Notice:
    • the inserted assignment it is surrounded by spaces
    • the action happen when the cursor is inside an R chunk or R script file

Notes

  • Working Directory is the location where R looks for files and store files. RStudio showed this location at the top of the console window. The location can be printed to the console using the R command getwd() (get working directory).
  • A data-science project typically contains multiple types of data. Each type is recommended to be kept in separate folder. These types of data are:
    • Data
    • Scripts
    • Results
    • Figures
  • When creating project using RStudio, a file with the extension .Rproj will be created. Clicking this file will automatically open the project in RStudio.
  • Whenever inside a project, one should only use relative paths (relative to the working directory, ie, the project home) except for file hosted on the internet which require using absolute paths.