Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to replace "unexpected escaped character" in R

When I try to parse JSON from the character object from a Facebook URL I got "Error in fromJSON(data) : unexpected escaped character '\o' at pos 130". Check this out:

library(RCurl)
library(rjson)
data <- getURL("https://graph.facebook.com/search?q=multishow&type=post&limit=1500", cainfo="cacert.perm")
fbData <- fromJSON(data)
Error in fromJSON(data) : unexpected escaped character '\o' at pos 130

#with RSONIO also error
> fbData <- fromJSON(data)
Erro em fromJSON(content, handler, default.size, depth, allowComments,  : 
invalid JSON input

Is there any way to replace this '\o' character before I try to parse JSON? I tried gsub but it didn't work (or i'm doing something wrong).

datafixed <- gsub('\o',' ',data)
Error: '\o' is an unrecognized escape sequence in string starting with "\o"

Can somebody hel me with this one? Thanks.

like image 459
Luiz Felipe Freitas Avatar asked Oct 04 '22 13:10

Luiz Felipe Freitas


1 Answers

You need to escape \ in your pattern.

Try

gsub('\\o',' ',data)
like image 122
CHP Avatar answered Oct 13 '22 11:10

CHP