R: What's the logic about when to use quotation marks and when not to?

I'm having a hard time remembering when I need to enclose things in quotes and when not to.
The easiest to remember is if there's a space between words but beyond that, I can't figure it out.
For example,
quotes are not used with: library(package_name) or head(variable_name),

but they are required with: install.packages("package_name"), ls(“package:package_name”), or read_csv(readr_example(“mtcars.csv”)).

Any ideas on how to help remember when to use them and when not to?

If you do not use quotes, R assumes you are refering to the name of an object, if you use quotes, it assumes you are simply entering a character string value.

#This defines an object 
object_name <- 2

# This is the name of an object
#> [1] 2

# This is a character string
#> [1] "object_name"

Created on 2021-08-17 by the reprex package (v2.0.1)

Wow, that makes it easy. I really appreciate that! Thanks a million!

This is an example where quotes would be "correct", but it works with and without quotes. You will mainly see without because it's easier to type.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.