Search code examples
rdouble-quotessingle-quotes

In R, why do style guides recommend that one only use double quotes?


The lintr package has a check for single-quoted strings, and single quotes are discouraged elsewhere (e.g. ?Quotes). Single and double quoted strings work identically in R, so is there a reason why single quotes are considered bad practice?

Citations to canonical documents especially welcome. To be clear: I'm asking about the reasons given by the R core team for discouraging single quotes; not about people's own opinions on the topic.


Solution

  • I guess because R by default prints using double quotes. This way the 'other quote character' in a string gets

    a) handled normally if its a single quote
    b) escaped when its a double quote

    when printing. Using double-quotes discourages the use of double-quotes in a string.

    Take the following example:

    Double Quoted

    "It's my car"
    

    Prints

    "It's my car"
    

    Single Quoted

    'It"s my car'
    

    Prints

    "It\"s my car"