[R] Why double quote is preferred?

Douglas Bates bates at stat.wisc.edu
Sat Feb 13 16:47:20 CET 2010


On Fri, Feb 12, 2010 at 4:25 PM, blue sky <bluesky315 at gmail.com> wrote:
> ?'`' shows the following:
>
> "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."
>
> It is not clear to me why double quote is preferred (I don't think
> that "character constants are printed using double quotes" should be
> the reason, in the sense that single quote can be used for printing if
> we want to do so). It seems that double quote and single quote can be
> used interchangeably, except that "Single quotes need to be escaped by
> backslash in single-quoted strings, and double quotes in double-quoted
> strings."
>
> Could somebody why double quote is preferred?

To avoid confusion for those who are accustomed to programming in the
C family of languages (C, C++, Java), where there is a difference in
the meaning of single quotes and double quotes.
A C programmer reads 'a' as a single character and "a" as a character
string consisting of the letter 'a' followed by a null character to
terminate the string.  In R there is no character data type, there are
only character strings.  For consistency with other languages it helps
if character strings are delimited by double quotes.  The single quote
version in R is for convenience.  On most keyboards you don't need to
use the shift key to type a single quote but you do need the shift for
a double quote.

P.S. I do not plan to get into an extended debate on this issue, Peng.
 (As others have pointed out, it is considered bad form to disguise
your identity on this list.)  Your opinions on the design of the
language have been noted but if you want the language to be redesigned
to your specifications, you will need to fork your own version.



More information about the R-help mailing list