-
Notifications
You must be signed in to change notification settings - Fork 6
/
help.Rmd
269 lines (181 loc) · 6.7 KB
/
help.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
269
---
title: "FAQ / Help"
output:
html_document:
toc: true
---
<br>
<br>
```{css, echo=FALSE}
.bg-error {
background-color: #fde4e4;
border: 2px solid #ce0707;
color: #ce0707
}
code{
background-color: #ffffff;
color: #000
}
```
# **Common Issues**
***
## **I'm getting an error related to something called Rtools**
You probably need some add-on software for a Windows machine. Note that this is _not_ an additional R package to install. Here is a quick guide to installing Rtools: [link](https://docs.google.com/viewer?url=https://raw.githubusercontent.com/jhudsl/intro_to_r/main/resources/rtools_windows.pdf).
***
## **What packages are part of the Tidyverse**?
If you need to check what packages are part of the `tidyverse`, you can do so at this [link](https://www.tidyverse.org/packages/).
***
## **Why are my changes not taking effect? It's making my results look weird!**
**Forgetting to assign your data to an object**
Often we are just printing our data and not either reassigning an existing object or creating a new object.
Here we are creating a new object from an existing one:
```{r}
new_rivers <- sample(rivers, 5)
new_rivers
```
Using just this will only print the result and not actually change `new_rivers`:
```{r}
new_rivers + 1
```
If we want to modify `new_rivers` and save that modified version, then we need to reassign `new_rivers` like so:
```{r}
new_rivers <- new_rivers + 1
new_rivers
```
If we forget to reassign this can cause subsequent steps to not work as expected because we will not be working with the data that has been modified.
***
## **Why do I have a `+` sign instead of the cursor `>` in the console?**
**Trouble with parentheses**
You may get a `+` sign instead of the cursor `>` in the console suggesting that you have not closed an open parentheses. Each instance of `(` should be followed by `)`.
Hit the "esc" key to restore your `>`, then fix/rerun your code.
***
## **When should I use quotes ("") or backticks (``)?**
Check out our [Guide on when to use quotes or backticks](https://jhudatascience.org/intro_to_r/resources/quotes_vs_backticks.html).
***
## **How do I know when to use the `pull()` function, instead of just using `select()`?**
Check out our [Guide on what functions require pulling values out first](https://jhudatascience.org/intro_to_r/resources/functions_for_vectors.html).
<br><br><br>
# **Common Errors**
***
## **Error in x : could not find function "y"**
**Forgetting to load a library or misspelling a function or package**
For example, we forgot `library(tidyverse)` below:
```{r, echo = FALSE}
unloadNamespace("tidyverse")
```
```{r, error = TRUE, class.error="bg-error"}
iris %>% pull(Species)
```
Below will not work because `str_detect` is missing a `t` at the end:
```{r, error = TRUE, message = FALSE, class.error="bg-error"}
library(tidyverse) # need this! This can be at the top of your file
iris %>% pull(Species) %>% str_detec("setosa")
```
This will not work because `library()` is misspelled:
```{r, error = TRUE, class.error="bg-error"}
libary(tidyverse)
```
***
## **Error: object 'X' not found**
**Forgetting to assign an object to start with**
This error is usually caused by forgetting to assign an object to start with, or not running the piece of code that assigns an object. If you never created `rivers2` and try to modify it like so:
```{r, error = TRUE, class.error="bg-error"}
rivers2 + 1
```
Make sure you run something like this, with the `<-` operator:
```{r}
rivers2 <- new_rivers + 1
rivers2
```
***
## **Error: unexpected ',' in ... / Error: unexpected ')' in ... / Error: unexpected 'X' in ...**
**Trouble with parentheses**
This error can be caused by missing parentheses. Such as:
```{r, error = TRUE, class.error="bg-error"}
library(dplyr)
all.equal((rivers+1, rivers)
```
It should be:
```{r}
all.equal((rivers+1), rivers)
```
You will also often get this error if you have the correct number of parentheses but wrong placement:
```{r, error = TRUE, class.error="bg-error"}
all.equal((rivers+1, rivers))
```
If you have too many parentheses like this (the last one is extra)... you will get this error:
```{r, error = TRUE, class.error="bg-error"}
all_equal((rivers+1), rivers))
```
***
## **Error: unexpected symbol in "x"**
**Not using quotes or backticks when needed**
You will need to use quotes for variable names that have spaces or unusual punctuation. It is best to avoid these and rename variables if a variable name has spaces.
```{r, echo = FALSE, class.error="bg-error"}
library(tibble)
df_quotes <- tibble("The Values" = c(1,2,3), "names" = c("A", "B", "C"))
```
```{r}
df_quotes
```
If we want to specifically pull out the column with the variable named `The Values` we need to use quotes or back ticks.
```{r}
df_quotes %>% pull(names) # this works fine! no spaces in `names`
```
```{r}
df_quotes %>% pull("The Values") # this works
```
```{r}
df_quotes %>% pull(`The Values`) # this works
```
```{r, error = TRUE, class.error="bg-error"}
df_quotes %>% pull(The Values) # this does not work!
```
***
## **Error: unexpected input in "x"**
**Copy+pasting quotation marks**
If you copy paste code form somewhere with curly quotation marks, it will not work.
```{r}
df_quotes %>% pull("The Values") # this works
```
```{r, error = TRUE, class.error="bg-error"}
df_quotes %>% pull(“The Values”) # this doesn't work
```
***
## **Error: `mapping` must be created by `aes()` / `ℹ` Did you use '%>%' or '|>' instead of '+'?**
**Forgetting to use `+` to add `ggplot2` layers**
This will not work:
```{r, error = TRUE, class.error="bg-error"}
ggplot(data = iris, aes(x = Species, y = Petal.Length)) %>%
geom_boxplot()
```
This will work:
```{r, out.width = "30%"}
ggplot(data = iris, aes(x = Species, y = Petal.Length)) +
geom_boxplot()
```
***
## **Error in +.gg: `ℹ` Did you accidentally put '+' on a new line?**
This will not work:
```{r, error = TRUE, class.error="bg-error", out.width = "30%"}
ggplot(data = iris, aes(x = Species, y = Petal.Length))
+ geom_boxplot()
```
This will work:
```{r, out.width = "30%", class.error="bg-error"}
ggplot(data = iris, aes(x = Species, y = Petal.Length)) +
geom_boxplot()
```
# **Preference Changes**
***
## **How do I get output to stop printing inside the Rmarkdown and only show it in the console? (How Ava has her setup?)**
**To change this, you will need to adjust the RStudio Settings.**
![Click the gear icon beside the knit button to expand the options menu. Select "Chunk Output in Console".](images/console_output1.jpg)
![You can select Remove Output. You should now see output in the console.](images/console_output2.jpg)
<br>
<br>
***
## **How do I change the color / theme?**
Go to the menu Tools > Global Options > Appearance. Choose a theme and apply!
<br>
<br>