String in R Programming Language: Introduction and Examples
Any value written within a pair of single quote or double quotes in R is treated as a string. Internally R stores every string within double quotes, even when you create them with single quote.
Rules Applied in String Construction
-
The quotes at the beginning and end of a string should be both double quotes or both single quote. They can not be mixed.
-
Double quotes can be inserted into a string starting and ending with single quote.
-
Single quote can be inserted into a string starting and ending with double quotes.
-
Double quotes can not be inserted into a string starting and ending with double quotes.
-
Single quote can not be inserted into a string starting and ending with single quote.
Examples of Valid Strings
Following examples clarify the rules about creating a string in R.
m
When the above code is run we get the following output −
[1] "Start and end with single quote"
[1] "Start and end with double quotes"
[1] "single quote ' in between double quote"
[1] "Double quote \" in between single quote"