+ - 0:00:00
Notes for current slide
Notes for next slide

RStudio IDE Pro Tips

Mind-Meld with the RStudio IDE

Garrick Aden-Buie Β· Mario Ferrini Β· Greg Wilson
RStudio, PBC
November 18, 2020
1

The test of the machine is the satisfaction it gives you. There isn't any other test. If the machine produces tranquility it's right. If it disturbs you it's wrong until either the machine or your mind is changed.

β€”Zen and the Art of Motorcycle Maintenance

2

Three Strategies for Satisfaction

Discover what the IDE can do for you

3

Three Strategies for Satisfaction

Mold the tool to your workflow

Discover what the IDE can do for you

4

Three Strategies for Satisfaction

Adapt your workflow

Mold the tool to your workflow

Discover what the IDE can do for you

5

There's always going to be a certain amount of friction

coding is hard, right

the goal is to reduce friction between you and thinking about your code

listen to the friction is a signal, listen to the things that disturb you

Set Up

πŸ’Ό usethis::use_course("gadenbuie/rstudio-ide-tips-demo")

Follow the Slides

πŸ•Έ https://rstudio-ide-tips.netlify.app

In the chat window

πŸ€” How do you and RStudio get along best and worst?

6

RStudio...

gets me

  • Everything in one place
  • 4 panes to work with
  • Projects + sane file paths
  • Additional tools like git
  • Rainbow parentheses!
  • Tooling for package development
  • Running lots of scripts in the job pane

gets me not

  • Color preview for CSS colors
  • Too many panes!
  • Paths can be tricky
  • Running lots of scripts
  • RStudio in other languages, like Spanish
  • Non-ASCII character paths
  • Having lots of tabs (or closing tabs)
7

Check Your Keyboard

Cmd ⌘

Option βŒ₯

Ctrl

Alt

πŸ‘ˆ

8

Set Up Your Workspace

  • Open R/00_general.R

  • What panes are available?

  • Where do you put them?

  • Drag to resize

  • Pane Layout

  • Half Screen

  • Full Screen

9

Move Between Panes

Press Ctrl + ...

1 β†’ Source

2 β†’ Console

3 β†’ Help

5 β†’ …

6 β†’ …

7 β†’ …

8 β†’ …

9 β†’ …

πŸ–– Stretch your fingers

10

Zoom To Pane

Press Ctrl + Shift + ...

1 β†’ Source

2 β†’ Console

3 β†’ Help

5 β†’ Files

6 β†’ Plots

7 β†’ Packages

8 β†’ Environment

9 β†’ Viewer

11

Zoom To Pane

Run this code and then press

Ctrl + Shift + 1

library(dplyr)
View(starwars)

12

Zoom To Pane

Run this code and then press

Ctrl + Shift + 1

library(dplyr)
View(starwars)

Pipe into View()

starwars %>%
filter(species == "human") %>%
View()
13

Zoom To Pane

Run this code and then press

Ctrl + Shift + 1

library(dplyr)
View(starwars)

Give your viewer a name

starwars %>%
filter(species == "human") %>%
View("humans")
14

Getting Around

Solve the mystery of the black_box() function...

Jump Anywhere

Go Back

Jump to Function

black_box()

F2

Jump to Help

comment(x) <- "..."

F1

15

Code Style

  • Jump to code_style.R

  • Use the styler package for magically clean code

  • Use identity() or I() to walk through pipe steps

  • Move code up/down to reorganize

  • Add new lines and fix indentation: Ctrl + I

  • Let your code breathe vertically!

    • Change order of selection in a select()

    • Use multiple cursors by Cmd + Opt +

16

I use Ctrl + Shift + S for style selection and Ctrl + Shift + Cmd + S for style file

Multiple cursors

Click to create new cursors Cmd/Ctrl + Opt/Alt +

Click and drag to select/create new cursors Opt/Alt + and drag

Create new cursors with the keyboard Cmd/Ctrl + Opt/Alt +

Create new cursors from selection Find and Add Next Find and Select All

17
  • Find all - Cmd + Alt + F

  • Find and Add Next - Cmd + D

Align Arguments and Assignment

If code is more vertical, alignment is easier.

  • Align blocks of similar arguments or names or anytime there's repetition

  • Alignment makes it easier to scan for problems

  • AlignAssign

18

Addins

addinslist β€” An addin to find and install great addins

Some Favorites

Make Your Own

19

Coming Soon to an RStudio Near You

New in RStudio 1.4 along with a few other awesome features

⭐ Command Palette

🌈 Rainbow Parens

πŸ‘“ Visual Markdown

🍱 New Source Column

πŸ’Ύ RStudio Preview

20

Organize Your Code

Add section labels by pressing Cmd/Ctrl + Shift + R

# Library -----------------------------------------------------------------

Browse section labels

21

Run Script as Background Job

Source as Local Job

Configure Job Settings

22
  • Default settings
  • Return results to environment
  • Watch progress in the console
  • Use objects from global env

Let It Go...

Restart R Session

Cmd + Shift + 0

Ctrl + Shift + F10

Run Up To Here

R Cmd/Ctrl + Opt/Alt + B

Rmd Cmd/Ctrl + Opt/Alt + P

Always start with a blank slate

usethis::use_blank_slate()

https://rstats.wtf/save-source.html

πŸŽ› Global/Project Settings

23

Use Projects

24

Use Projects

25

Infinite Moon Reader

Automatically renders an R Markdown document whenever you save πŸ’Ύ

  1. Jump to docs/try/infinite_moon_reader.Rmd

  2. Edit the document and press save to see it in action

26
  • Show extract variable
  • Show insert new chunk
  • Show insert new chunk within a chunk

Resources for learning more

27

Resources for learning more

28

Bonus Round

29

Snippets

Global Options β†’ Code β†’ Edit Snippets

30

Snippets

Global Options β†’ Code β†’ Edit Snippets

Snippet Syntax

snippet s3generic
${1:generic} <- function(x, ...) {
UseMethod("${1:generic}", x)
}
${1:generic}.${2:method} <- function(x, ...) {
${0}
}
31

Snippets

Global Options β†’ Code β†’ Edit Snippets

Snippet Syntax

snippet s3generic
${1:generic} <- function(x, ...) {
UseMethod("${1:generic}", x)
}
${1:generic}.${2:method} <- function(x, ...) {
${0}
}

Try this one: shinymod

32

Themes

A collection of many RStudio themes

garrickadenbuie.com/project/rsthemes/

Install and try themes

remotes::install_github("gadenbuie/rsthemes", dependencies = TRUE)
rsthemes::install_rsthemes()
rsthemes::try_rsthemes()
33

rsthemes addins

πŸŒ‡ Toggle Dark Mode

πŸŒ‰ Auto Choose Dark or Light Theme

❀️ Next Favorite Theme

34

Assign shortcuts to addins

Toggle Dark/Light

Ctrl + Option + D

Next Favorite Theme

Ctrl + Option + N

35

Keyboard Shortcuts

Reference

Your Turn

Take 3 minutes to create new shortcuts for

  • Find and Add Next

  • Find and Select All

03:00
36

Decorate RStudio

πŸŽ› There are many options to check and adjust in Global Options

Code > Display

37

Decorate RStudio

πŸŽ› There are many options to check and adjust in Global Options

Code > Display

Appearance

  • Fonts

  • Themes

38

Decorate RStudio

πŸŽ› There are many options to check and adjust in Global Options

Code > Display

Appearance

  • Fonts

  • Themes

Hasklig

Hasklig Sample

Source Code Pro

Source Code Pro Sample

39

The test of the machine is the satisfaction it gives you. There isn't any other test. If the machine produces tranquility it's right. If it disturbs you it's wrong until either the machine or your mind is changed.

β€”Zen and the Art of Motorcycle Maintenance

2
Paused

Help

Keyboard shortcuts

↑, ←, Pg Up, k Go to previous slide
↓, β†’, Pg Dn, Space, j Go to next slide
Home Go to first slide
End Go to last slide
Number + Return Go to specific slide
b / m / f Toggle blackout / mirrored / fullscreen mode
c Clone slideshow
p Toggle presenter mode
t Restart the presentation timer
?, h Toggle this help
oTile View: Overview of Slides
Esc Back to slideshow