To declare a character or a string on R, one can use both following ways:
x <- 'Some string'
x <- "Some string"
Both work, but is there any difference ?
From ?"'"
:
Details
Three types of quotes are part of the syntax of R: single and double quotation marks and the backtick (or back quote, `). In addition, backslash is used to escape the following character inside character constants.
Character constants
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.
Backslash is used to start an escape sequence inside character constants. Escaping a character not in the following table is an error.
Single quotes need to be escaped by backslash in single-quoted strings, and double quotes in double-quoted strings.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With