In a sentence: To use multiple quotation marks in R
, escape the quotation marks of the text or enclose the text in quotation marks other than the quotation marks used in the text.
In greater detail
r does not differentiate double or single quotes to designate vector of class character
.
"Um texto" # duplas
# [1] "Um texto"
'Um texto' # simples
# [1] "Um texto"
The thing changes, however, within string
. In this case, R
seeks to preserve past information (as the question itself demonstrates).
'select * from probes."probes_97_2018-06" LIMIT 2'
# [1] "select * from probes.\"probes_97_2018-06\" LIMIT 2"
The same result can be obtained with double quotation marks, but for this we need to escape the quotes that go within string
. Otherwise, R
would think that we are ending the string and would expect to find an interpretable code in the part that follows ( probes_97_2018-06
).
# sem escapar as aspas
"select * from probes."probes_97_2018-06" LIMIT 2"
# Erro: unexpected symbol in ""select * from probes."probes_97_2018"
This can be avoided by escaping the quotation marks
# aspas de dentro escapadas
"select * from probes.\"probes_97_2018-06\" LIMIT 2"
# [1] "select * from probes.\"probes_97_2018-06\" LIMIT 2"
Equality between the two types of external quotes can be observed with
"aspas" == 'aspas'
# [1] TRUE
Finally, we can have all types of quotes inside a string
.
"string em aspas duplas com aspas \"duplas\" e 'simples'"
# [1] "string em aspas duplas com aspas \"duplas\" e 'simples'"
'string em aspas simples com aspas "duplas" e \'simples\''
# [1] "string em aspas simples com aspas \"duplas\" e 'simples'"