Rstudio tips

Run a line or run the whole document.

Keyboard shortcuts

Run a line:

ctrl-enter
cmd-enter

Search all files in a directory:

ctrl-shift-f
cmd-shift-f

Here are some others

  • Ctrl + L = clear commands
  • Ctrl + 2 = move cursor to console
  • Ctrl + 1 = move cursor to script page

Code autocompletion and help

tab inside parentheses:

library(ggplot2)
ggplot()

File path autocompletion

try(source(""))

Installing packages is easy

Tools –> install packages

Foldable regions

You can fold sections of your code within an R script.

## fold this -------------------

### or this =======================

Insert sections

code–> insert section (with .R file) cmd-shift-i code–> insert chunk (with .Rmd file) cmd-alt-i

Code snippets

press tab after these:

appl

ts

Addins

install.packages("addinslist")

View Data Sets

View(mtcars)

Debugging + Code Diagnostics

Rstudio –> preferences –> Code –> debugging –> check all boxes

R studio can debug some of your code in real time, also has other debugging tools built in, such as browser().

A longer tutorial is here

Start a shell

Tools -> Shell

New features with every release

Currently in the “preview” release is built in profiling (determining the time each part of code takes to run)

Reproducibility

rm(list=ls())
mydata = read.table("../data/myfile.csv")