args <- commandArgs(trailingOnly = TRUE)
id = as.character(args)
mysqlconnection = dbConnect(MySQL(), user = 'root', password = '', dbname = 'manu',host = 'localhost')
sql<-sprintf("select * from net where ips1=%s;",id)
up = dbGetQuery(mysqlconnection, sql)
我正在尝试使用 R 从表网络中检索记录。 我想检索具有特定 id 的记录,该 id 作为命令行参数传递。但是我在“ips1=%s ”附近收到错误,说我使用的 SQL 语法不正确。有什么帮助吗?
最佳答案
请尝试将要比较的字符串值括在单引号中 '
:
sql <- sprintf("select * from net where ips1='%s';",id)
关于R中的MySQL查询与特定值进行比较,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37960002/