Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R character/string: '...' vs "..."

Tags:

r

character

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 ?

like image 745
JohnBee Avatar asked Feb 08 '23 07:02

JohnBee


1 Answers

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.

like image 131
talat Avatar answered Feb 16 '23 04:02

talat