I need to remove all the backslash in a string like below.
x <- ' [{\"Petal.Width\" : 1.8, \"Species\" : \"virginica\" } ] '
The resulting string I want is
[{"Petal.Width" : 1.8, "Species" : "virginica" } ]
I tried some methods which don’t work.
gsub("\\\\", "\\", x)
Could any people suggest some methods? Many thanks!
The backslashes are R’s way of escaping quotation marks within a character string (see
?Quotes). It is unlikely that you’ll have to remove them. For example, if you’re looking to use your objectxas a title for a plot, the backslashes will not appear: