-
Notifications
You must be signed in to change notification settings - Fork 1
/
01_ide.Rmd
268 lines (164 loc) · 4.81 KB
/
01_ide.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
---
title: "IDE"
subtitle: "Part 1 of the RStudio Tips and Tricks Series"
author: "Jeremy Allen"
date: "Nov 2, 2021, updated on `r Sys.Date()`"
output:
html_document:
highlight: zenburn
theme:
bg: "#303436"
fg: "#9da9af"
primary: "#ff8080"
base_font:
google: "Roboto"
code_font:
google: "JetBrains Mono"
editor_options:
chunk_output_type: console
self_contained: true
---
------------------------------------------------------------------------
Slides for the RStudio Tips and Tricks Series:
<https://jeremy-allen.github.io/rstudio-tps/>
Code:
<https://github.com/jeremy-allen/rstudio-tips>
------------------------------------------------------------------------
<br>\
<br>
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
```{r packages, echo=TRUE, message=FALSE, warning=FALSE}
library(palmerpenguins)
library(tidyverse)
library(janitor)
library(here)
```
# Before we dive in, two things
## Set preview in viewer pane
![viewer pane](images/viewer_pane.gif "viewer pane setting")
<br>
## Visual Editor will be our quick preview tool throughout this series
![Visual Editor](images/ve.gif "Visual Editor")
<br>
# Adjusting Global Options in the RStudio IDE
`r emo::ji("smile")` Pro tip: cmd+, to access global options
<br>
### Rearrange panels
![](images/panels.png)
<br>
### Change theme
![](images/theme.png)
<br>
### Show chunk output in console
![](images/output.png)
<br>
### Default R version & don't save workspace data
![](images/r_version.png)
<br>
### Set repo for RStudio Public Package Manager
`r emo::ji("smile")` Pro tip: If you are on a Linux server, see what operating system you are on by running this in your console:
<br>
`system("lsb_release -a")`
<br>
Then go to [RStudio Public Package Manager](https://packagemanager.rstudio.com/client/)
![](images/rspm.png)
![](images/set_rspm.png)
<br>
## Allow scroll past end of doc & rainbow parentheses
![](images/scroll.png)
<br>
## Command Palette is amazing!
`r emo::ji("smile")` shift+cmd+p then do anything
Use shift+cmd+p to access the command palette and:
- Toggle Memory Usage Display in Environment Pane
- Syntax highlighting in console output
- Knit Current Document
- Highlight Selected Line
<br>
## Adjust the code chunk options at the top of this file to hide code and re-knit
<br>
## Expand the outline
`r emo::ji("smile")` Pro tip: Navigate your document with the outline
`r emo::ji("smile")` also ctl+shift+o
![](images/out1.png)
![](images/out2.png)
<br>
## Outline is also down here
![](images/out3.png)\
<br>
# Code folding
Go back up to the line "set repo for RStudio Public Package Manager"\
`r emo::ji("smile")` Click the little triangle next to the line number
![](images/fold.gif)\
<br>
# Command History in the console
`r emo::ji("smile")` Pro tip: in the console type a couple of letters then cmd+up for visual of matches
![](images/history.gif)
<br>
# Open File in New Column
`r emo::ji("smile")` Pro tip: open file in new column is great for Shiny apps when you have ui, sever, and css files
![](images/columns.gif)\
<br>
# Comment and not
`r emo::ji("smile")` Pro tip: highlight multiple lines of code, shift+ctl+c to comment all
![](images/comments.gif)
<br>
# Move line
`r emo::ji("smile")` Pro tip: alt+up or alt+down to move lines
![](images/move.gif)
<br>
# Multi-line
`r emo::ji("smile")` Pro tip: ctl+alt+down or ctl+alt+up to have multi-line cursor\
You try: add commas after starts_with() and mean
```{r echo=TRUE, eval=FALSE}
df %>%
summarise(
across(
starts_with("culmen")
mean
na.rm = TRUE
)
)
```
![](images/multi.gif)
<br>
# Which parentheses?
`r emo::ji("smile")` Pro tip: double click one of the parentheses to highlight what it contains
```{r echo=TRUE, eval=FALSE}
div(
class = "outer",
div(
class = "container",
div(
class = "data",
df %>%
filter(
str_detect(Species, "Chin"),
Sex == "MALE",
Island == "Dream"
) %>%
summarise(
across(
starts_with("culmen"),
mean,
na.rm = TRUE
)
)
)
)
)
```
![](images/parens.gif)
<br>
# Execute long-running code in jobs
`r emo::ji("smile")` Pro tip: execute code or scripts as jobs in separate R sessions so you can keep working in your IDE
![Jobs](images/job1.gif)
# git in the IDE (a very short intro)
`r emo::ji("smile")` Pro tip: ctl+alt+m to open the commit window\
`r emo::ji("smile")` Pro tip: can stage or discard chunks, even lines\
`r emo::ji("smile")` Pro tip: select first file then cmd+a to highlight all, then check one to check all
![Git discard](images/git_discard.gif)
<br>
[more on git in RStudio](https://r-pkgs.org/git.html#git-rstudio)