I\'m working in an R script that uses a long SQL string, and I would like to keep the query relatively free of other markup so as to allow copying and pasting between editor
you can override the %+% operator to have better string concatination syntax:
'%+%' <- function(x,y) paste(x,y,sep="")
y<-"y1"
x<-"somethingorother"
query<-
'SELECT DISTINCT x AS ' %+% x %+%',\n' %+%
' y AS ' %+% y %+% '\n' %+%
' FROM tbl
WHERE id=%s
AND num=%d'
cat(query,"\n")
yields:
> cat(query,"\n")
SELECT DISTINCT x AS somethingorother,
y AS y1
FROM tbl
WHERE id=%s
AND num=%d