Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to print double quotes (") in R

Tags:

r

I want to print to the screen double quotes (") in R, but it is not working. Typical regex escape characters are not working:

> print('"')
[1] "\""
> print('\"')
[1] "\""
> print('/"')
[1] "/\""
> print('`"')
[1] "`\""
> print('"xml"')
[1] "\"xml\""
> print('\"xml\"')
[1] "\"xml\""
> print('\\"xml\\"')
[1] "\\\"xml\\\""

I want it to return:

" "xml" "

which I will then use downstream.

Any ideas?

like image 817
frank Avatar asked May 25 '16 07:05

frank


People also ask

How do you do double quotes in R?

With an escape character, however, adding a double quote inside your string is easy, you simply prepend the double quote with the backslash.

How do I print double quotes in printf?

\" - escape sequence Since printf uses ""(double quotes) to identify starting and ending point of a message, we need to use \" escape sequence to print the double quotes.

What is use of quote () function in R?

quote() returns an expression: an object that represents an action that can be performed by R. (Unfortunately expression() does not return an expression in this sense. Instead, it returns something more like a list of expressions. See parsing and deparsing for more details.)

How do I add quotes to a string in R?

To add single quotes to strings in an R data frame column, we can use paste0 function. This will cover the strings with single quotes from both the sides but we can add them at the initial or only at the last position.


2 Answers

Use cat:

cat("\" \"xml\" \"")

OR

cat('" "','xml','" "')

Output:

" "xml" "

Alternative using noqoute:

 noquote(" \" \"xml\" \" ")

Output :

 " "xml" " 

Another option using dQoute:

dQuote(" xml ")

Output :

"“ xml ”"
like image 144
Ani Menon Avatar answered Sep 28 '22 13:09

Ani Menon


With the help of the print parameter quote:

print("\" \"xml\" \"", quote = FALSE)
> [1] " "xml" "

or

cat('"')
like image 40
sebastianmm Avatar answered Sep 28 '22 11:09

sebastianmm