Wednesday, June 17, 2015

Rstudio tips - Key bindings to program and explore data with R


Rstudio is an editor for the R statistical programming language which can be installed on windows, mac and Linux. See my post explaining R setup under Debian.

Edit code

  • TAB auto complete object names
  • F1 on a function name shows the help page of that function
  • F2 on a function name jumps to the code where that function was created. I found this key so useful that I decided to created this blog post.
  • CTRL+W  close a tab
  • CTRL+F find and replace text
  • CTRL+SHIFT+F find in all files in a directory (like grep), then click on results lines to jump in the files

Explore data

In the environment window, click on a data frame to view it then click on filter to filter the data frame according to various criteria.

Create pdf or html reports

When editing a markdown .Rmd document, the pdf or html report can be generated with CTRL+SHIFT+K.

Create a package

The R packages book by Hadley Wickham explains how to create R packages. Useful short-cuts when working with packages:
  • CTRL+SHIFT+B build the package
  • CTRL+SHIFT+D generate documentation
  • CTRL+SHIFT+T run devtools::test()
The documentation step can be set to run automatically with the package building under build / configure build tools / generate documentation with Roxygen / configure.

Vim mode

Vim mode can be activated under Tools / Global options / Code. Enter command mode with ":" and ask for ":help".  I use primarily the following keys:
  • jklhw$ggG navigate text
  • iaoA enter edit mode to insert text
  • Escape return to navigation mode
  • v select text
  • ypP copy selected text and paste
  • d delete 
  • /nN search