library(emoji)
library(tidyverse)
Road Less Traveled 🛶
Productive RStudio IDE features you may not know
…and some you will
Note
I am on a MacBook so cmd
= command key. If you are on a Windows machine, use ctl
instead
❤️ Jeremy’s personal favorites
Output to where?
I like it to go to the console
- ⚙️ -> Chunk Output in Console
Console is where?
I move my console to the top right quadrant: Tools->Global Options->Pane Layout
Function bodies
- F2 or
cmd+click
the function name to expose function body
- Don’t forget to select a method in the drop down if you can
- F1 the function name for help
- My favs because I learn best by seeing what others are already doing 🧠
# HINT: load the tibble package first
<- tibble::as_tibble(diamonds) dat
View the data in a tab
cmd+click
the tibble name- search whole table
- filter columns
🧭 Getting around
Command Palette
It’s not unknown, but it’s so productive I cannot not mention it
shift+cmd+p
- once in there, type Global Options and return
- explore Global Options
- keybindings, vim anyone?
- relative line numbers
- highlight function calls (toggle in Command Palette)
Outline is not out of line
ctl+shift+o
to navigate your document with the outline on the right- Also access outline and functions at the bottom of the doc
Death by a thousand tabs
- Go to file/function window - find function grow_city()
ctl+.
to search file tabs
It’s ok to cheat - I don’t believe they’ve been here all along
- Help -> Cheat Sheets
- What? There’s one for the IDE? 🧐
💻 Code mode
Editor fun
shift+ctl+c
to comment all highlighted linesalt+up
oralt+down
to move linesctl+alt+down
orctl+alt+up
oralt+drag
to have multi-line cursorcmd+i
to fix indention in highlighted codecmd+shift+m
to insert pipe, but which pipe? Seeshift+cmd+p
- in the console, what does
up
do? what aboutcmd+up
? - double-click parentheses to highlight contents
|>
dat ::ggplot(aes(x = carat, y = price, color = cut)) +
ggplot2geom_point(alpha = .3) +
labs(
title = "Diamonds: Price as a Function of Carat",
subtitle = "by cut",
x = NULL,
y = NULL
+
) theme_minimal()
Snippets
shift+tab
to expand a snippet- type fun then
shift+tab
- don’t stop now, do
if
andfor
as well - shinyapp then
shift+tab
# try fun, for, if, and shinyapp here
# try demoplot here
- Tools -> Edit Code Snippets to see them all and make your own
🏥 Search and Rescue
- find and replace across files
shift+cmd+f
and search for good_pets, then replace- but wait, let’s only look in .R files, so use custom filter
🪲 Bugs
Breakpoints and browser()
Let’s jump over to the my_func.R
file for this piece
- step through the body of a function
- see variable values along the way
- choose which environment to see
🆒 Visual editor
normal doc styling features
insert links, pics, tables, citations, footnotes, and more
Here are two citations (Little, Loughland, and Seebacher 2020; Melnychuk et al. 2016); and a reference section will be added to the doc
add more here:
📦 Advanced
⛓️ Connections
The IDE installs Posit’s pro drivers for you
In the Connections pane
- click New Connection
- chose a driver
- the IDE installs it before helping you start the connection
- if the install fails, update packages and try again 🔌
Requires writing packages
Templates
Addins
So Much More
Have you tried background jobs yet?
Tip: you can activate one from inside an R file - Source -> Source as Background Job
References
Little, Alexander G., Isabella Loughland, and Frank Seebacher. 2020. “What Do Warming Waters Mean for Fish Physiology and Fisheries?” Journal of Fish Biology 97 (2): 328–40. https://doi.org/10.1111/jfb.14402.
Melnychuk, Michael C., Emily Peterson, Matthew Elliott, and Ray Hilborn. 2016. “Fisheries Management Impacts on Target Species Status.” Proceedings of the National Academy of Sciences 114 (1): 178–83. https://doi.org/10.1073/pnas.1609915114.