
sQuote(x)
dQuote(x)
x
(after any coercion)
in the current locale's encoding.options
setting for
useFancyQuotes
. If this is FALSE
then the undirectional
ASCII quotation style is used. If this is TRUE
(the default),
Unicode directional quotes are used are used where available
(currently, UTF-8 locales on Unix-alikes and all Windows locales
except C
): if set to "UTF-8"
UTF-8 markup is used
(whatever the current locale). If set to "TeX"
, TeX-style
markup is used. Finally, if this is set to a character vector of
length four, the first two entries are used for beginning and ending
single quotes and the second two for beginning and ending double
quotes: this can be used to implement non-English quoting conventions
such as the use of guillemets. Where fancy quotes are used, you should be aware that they may not be
rendered correctly as not all fonts include the requisite glyphs: for
example some have directional single quotes but not directional double
quotes.
This is particularly troublesome in Windows ‘Command Prompt’
windows, which by default are set up to run in the so-called OEM
codepage, which in most locales uses a different encoding from
Windows. Further, if the codepage is changed (with chcp.exe
,
e.g. to 1252 in a Western European language), the default raster fonts
do not support the directional quotes. To work around this, the default for options("useFancyQuotes")
is FALSE
on Windows except for the Rgui
console. There
fancy quotes work with the default Courier New font and more elegantly with
Lucida Console and default East Asian fonts, but directional double
quotes are missing in raster fonts such as Courier and FixedSys.shQuote
for quoting OS commands.op <- options("useFancyQuotes")
paste("argument", sQuote("x"), "must be non-zero")
options(useFancyQuotes = FALSE)
cat("\ndistinguish plain", sQuote("single"), "and",
dQuote("double"), "quotes\n")
options(useFancyQuotes = TRUE)
cat("\ndistinguish fancy", sQuote("single"), "and",
dQuote("double"), "quotes\n")
options(useFancyQuotes = "TeX")
cat("\ndistinguish TeX", sQuote("single"), "and",
dQuote("double"), "quotes\n")
if(l10n_info()$`Latin-1`) {
options(useFancyQuotes = c("\xab", "\xbb", "\xbf", "?"))
cat("\n", sQuote("guillemet"), "and",
dQuote("Spanish question"), "styles\n")
} else if(l10n_info()$`UTF-8`) {
options(useFancyQuotes = c("\xc2\xab", "\xc2\xbb", "\xc2\xbf", "?"))
cat("\n", sQuote("guillemet"), "and",
dQuote("Spanish question"), "styles\n")
}
options(op)
Run the code above in your browser using DataLab