I am a novice R user and definitely new with the xml format, so forgive me if there is an obvious answer to this question.
I am trying to create a data frame with specific objects from an xml file, and am running into some issues.
I've saved the xml content into a data frame and use the "fromJSON()" command to convert it to something usable in R so I can reference certain parts of the content using an array. However, for a select few of these observations, I get the following error:
"Error in parseJSON(txt) : lexical error: inside a string, '\' occurs before a character which it may not."
Someone I know suggested this error may have occurred because the parseJSON function is trying to interpret the ‘\’ as an escape character. I've since tried to replace all backslashes with double backslashes without much luck. I did notice that while using the gsub command, a single backslash was not interpretable in R, so I replaced with a double backslash, but also with no luck. I've also tried skipping over the backslashes using the scan function. Here is the code that I've tried:
res <- gsub('\\','\\\\',res)
res = scan(res,allowEscapes=F)
When I run gsub above, I get an error involving trailing backslashes. When I run scan, the file is uninterpretable by R. I also still want to be able to reference objects in R, so I'm not sure if using something other than '\' would be appropriate.
Could someone help me out?
No comments:
Post a Comment