解决方法
您可以覆盖%%运算符以获得更好的字符串连接语法:
'%+%' <- 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")
收益率:
> cat(query,"\n") SELECT DISTINCT x AS somethingorother,y AS y1 FROM tbl WHERE id=%s AND num=%d