如何正确分配具有%in%的monet.frame

时间:2013-11-26 23:12:51

标签: r monetdb

如果

,似乎一切正常
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位)

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特定问题。只是不知道如何规避它。

感谢。

1 个答案:

答案 0 :(得分:3)

首先,感谢合作中产生的非常好的错误报告。我之前遇到过这个问题,它应该在R-Forge(https://r-forge.r-project.org/R/?group_id=1534)上提供的软件包的0.8.1版本中修复。