Solve the Double qoutes within double quotes issue in R

r

Solution

Are you parsing string input from a file or standard input of something?

`scan(what='character',sep='\n')` will read data from the `stdin()` and automatically escape the quotes. Same if from a file

>scan(what="character",sep="\n",allowEscapes=T)
1: I'm watching "Prometheus"
2: 
Read 1 item
[1] "I'm watching \"Prometheus\""
>
>scan(what="character",sep="\n",allowEscapes=T)
1: "I'm watching "Prometheus""
2: 
Read 1 item
[1] "\"I'm watching \"Prometheus\"\""

Once you've got your input you could use a regular expression to replace the escaped inner quotes... (I think! - might be a complicated reg exp)

Problem

With R, when we put double quotes inside a double quotes: ``` y <- " " " " ``` It will end out Error: unexpected string constant in "y <- " " " "" My question is how to remove all the double quotes detected or convert into single quotes within the main double quotes. For example: ``` y <- "I'm watching "Prometheus"." y ``` The desired result is ``` #[1] "I'm watching Prometheus." ``` or ``` #[1] "I'm watching 'Prometheus'." ```

Original source