The easiest approach for your use case may just be writing some wrapper function that escapes all of those characters for you. For example something like this should work:
escape.quote <- function(){
s <- paste(scan(what=character(),sep="\n"),collapse=" ")
s <- gsub('"','\"',s)
s <- gsub("'","\'",s)
return(s)
}
Then you can just insert this in your sqldf()
calls and copy and paste your queries there. Like so:
> library(sqldf)
> set.seed(2)
> DF <- data.frame(g=rep(1:2,5),v=rnorm(10))
> sqldf(escape.quote())
1: select g,
2: avg(v) as avg_v
3: from "DF"
4: group by g
5:
Read 4 items
g avg_v
1 1 0.6606215
2 2 -0.2383182