When starting out learning R, it can be very confusing in which cases you have to put something in quotes / quotation marks and when you don't.
For example, when calling the column mpg from mtcars, I use quotes when using the [ notation but omit them when using the $. The output however is identical.
unquoted <- mtcars$mpg
quoted <- mtcars[,"mpg"]
identical(unquoted,quoted)
#> [1] TRUE
It get's even more complicated when I use tidyverse functions. Are there some general rules on when to use quotes and when not to?
PS: I'm asking this question on behalf of many confused students.
Here are some general rules from the top of my head:
When to use quotes
[install.packges("mypackage")library("mypackage")(here, you don't have to quote)When not to use quotes
TRUE/FALSEgroup_by,mutate,summarise,ggplot,pivot_*,*_join)$sign (e.g.df$mycolumn. However, you could use quotes)