Dynamic “string” in R

牧云@^-^@ 提交于 2019-11-26 23:18:15
Joshua Ulrich

We can use paste:

Df <- sqlQuery(ch, paste("SELECT * FROM tblTest WHERE Id =", Id))

c concatenates into a vector, paste is for string concatenation.

Or we can use sprintf:

sprintf("SELECT * FROM tblTest WHERE Id = %s", Id)

If you have multiple or reused arguments and a query that contains % you can use something like the following:

sprintf("SELECT * FROM test WHERE id = %1$s AND name = %2$s and type like ‘%%tall%%’”, id, name)
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!