似乎一切都好,如果
subset(mdf, id %in% c("A","B"))
但如果错误
ids = c("A","B")
subset(mdf,id %in% ids)
以下是演示代码:
con1 = dbConnect(dbDriver("MonetDB"),"monetdb://go:50000/voc")
d = data.frame(id=base::sample(c("A","B","C","D"),100,replace=T),v=sample(1:10,100,replace=T),stringsAsFactors=F)
head(d)
str(d)
dbWriteTable(con1, "test", d)
mdf <- monet.frame(con1,"test")
subset(mdf, id %in% c("A","B"))
ids = c("A","B")
subset(mdf,id %in% ids)
MonetDB.R_0.8.0 DBI_0.2-7
R 版本 3.0.2 (2013-09-25) 平台:x86_64-pc-linux-gnu (64-bit)
subset(mdf, id %in% c("A","B"))
实际转换为 sql 为:
MonetDB-backed data.frame surrogate
2 columns, 44 rows
Query: SELECT * FROM test WHERE ( (id IN ('A','B')) )
Columns: id (character), v (numeric)
错误消息
IDS = c("A","B")
subset(mdf,id %in% IDS)
是这样的:
Error in .local(conn, statement, ...) :
Unable to execute statement 'SELECT COUNT(*) FROM test WHERE ( (id IN 'AB') ) '.
Server says 'syntax error, unexpected STRING, expecting '(' in: "select count(*) from test where ( (id in 'AB'"' [#42000].
我猜这是MonetDB.R的特定问题。只是不知道如何规避它。
谢谢。