I'm having trouble processing a file in R. I've seen that backslashes are difficult to deal with in R, but that question is old and I'm hoping that someone has something that will help. Here's an example that works as expected:
" \"IRIS1003\": {" -> x
gsub('\"','XX', x)
After this, x contains XXIRIS1003XX": {. However, I want to simply remove the backslashes, rather than treating them as escape characters for the double quotes. I.e., I want to keep the double quotes so that the result is that x contains "IRIS1003": {. I suppose I could do this in two steps - the gsub() that I just did followed by replacing the XX, but I'd rather do this in a single step because the larger file might originally contain the string XX. Any ideas?
print()method to show that the double quotes are part of the string, not string ending. If you display your string withcat(x)it will display without the backslashes and get you your desired result. But you do not need to modify the string to get there because your string does not contain any backslashes even ifprint()shows them.jsonlite::fromJSON("{\"IRIS1003\":\"Test\"}")see fromJSON. 'I want to keep the double quotes so that the result is that x contains "IRIS1003": {' - you already have that. To quote this R always displays strings in double-quotes. That \ tells R to “escape” the next character. In this case, the \" is saying, " is part of the string, not the end of the string.