In a sentence: to use multiple quotes in R, escapes the quotation marks of the text or wraps the text in quotation marks other than the quotation marks used in the text.
In more detail
The r does not differentiate double or single quotes to designate class vector character.
"Um texto" # duplas
# [1] "Um texto"
'Um texto' # simples
# [1] "Um texto"
The picture changes, however, within the string. In this case, the R seeks to preserve past information (as the question itself shows).
'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 quotes, but for this we need to escape the quotes that go inside the string. Otherwise, the R would think that we are finishing the string and would expect to find an interpretable code in the following part (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"
The equality between the two types of external quotation marks can be observed with
"aspas" == 'aspas'
# [1] TRUE
Finally, we can have all kinds of quotation marks 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'"
And do single quotes inside double quotes work? type dbGetQuery(rabbit,"select * from Probes. 'probes_97_2018-06' ")
– hugocsl
Have you tried the back Votes? (Sorry about the English.)
– Rui Barradas
Thanks!!! In format
dbGetQuery(coelho,"select * from probes.'probes_97_2018-06' LIMIT 2")does not work, but in the graduatedbGetQuery(coelho,'select * from probes."probes_97_2018-06" LIMIT 2')worked.– Márcio Mocellin
Now I was curious to know why so Lucina and more when I do:
> 'select * from probes."probes_97_2018-06" LIMIT 2'returns[1] "select * from probes.\"probes_97_2018-06\" LIMIT 2"– Márcio Mocellin
If you do so should work too, using the back-Slash in single quote.
dbGetQuery(coelho,"select * from probes.\'probes_97_2018-06\' ")But note that from the documentation it seems that there is a concatenation of Quotation Marks that should be followed from the first Quotation Marks! The following are references taken from the documentation. https://stat.ethz.ch/R-manual/R-devel/library/base/html/Quotes.html– hugocsl
In Postgresql quotes(") have a special meaning: they indicate a delimited identifier or quoted Identifier. It is formed by placing an arbitrary string of characters between quotation marks and is interpreted as an identified and
– anonimo