In R, is there a difference between double and single quotes?

Asked

Viewed 69 times

2

I am starting my learning in R and would like to know the difference between creating strings using single or double quotes. For example:

texto1 <- "isso é um texto"
texto2 <- 'isso é um texto'

Is there any difference between the above cases? Is there any situation that you are required to use single or double quotes?

1 answer

6


According to the documentation of the R, no difference for most applications, although double quotes are preferred:

Single and double Quotes delimit Character constants. They can be used interchangeably but double Quotes are Preferred (and Character constants are printed using double Quotes), so single Quotes are normally only used to delimit Character constants containing double Quotes.

However, there are special cases where the order used to declare the quotation marks may lead to errors in the interpretation of the program. But in the traditional cases of using quotation marks, as simple string declaration, can be created using ' or " without needing further care.

print("Ola, Mundo!")
## "Ola, Mundo!"

print('Ola, Mundo!')
## "Ola, Mundo!"

print("'Ola, Mundo!'")
## "'Ola, Mundo!'"

print('"Ola, Mundo!"')
## "\"Ola, Mundo!\""

print(""Ola, Mundo!"")
## Error: unexpected symbol in "print(""Ola"

print(''Ola, Mundo!'')
## Error: unexpected symbol in "print(''Ola"
  • 1

    Thank you very much!

  • Dispose! Well formulated questions are a pleasure to answer.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.