将 R 连接到 RStudio 上的嵌入式 H2 数据库

Connecting R to embedded H2 database on RStudio

我很难弄清楚如何将我的 R 代码连接到嵌入式 H2 数据库。好像是 RH2 is the tool to go with (library is installed) but there is no working example on the documentation nor on stackexchange or on Google - at least I didn't find one (besides this)。由于我正在使用 R 做我的婴儿学步,一个连接和检索数据的工作示例会很棒!

代码必须类似于

library(RH2)
options(RH2.jars = "C:\h2\bin\h2-1.4.187.jar")
myH2 <- H2(driverClass="org.h2.Driver",
   identifier.quote="\"", jars = getOption("RH2.jars"))
con <- dbConnect(myH2,
   url = "jdbc:h2:C:\data\sample.h2.db", 
   user = "admin", password = "ultrasafe123")
dataFrame = fetch(dbGetQuery(con, "select * from TABLENAME"))

目前我得到:

Error in .jfindClass(as.character(driverClass)[1]) : 
    class not found` from `driverClass="org.h2.Driver"`

但这正是文档中显示的方式。我错过了什么吗?图书馆?包括 library(RJDBC) 也没有帮助。

我终于自己解决了:

library(RH2)
myH2 <- H2('org.h2.Driver', 'C:/h2/bin/h2-1.4.187.jar')
## location of h2 file: C:\data\data.h2.db 
con <- dbConnect(myH2, "jdbc:h2:C:/data", "user", "password")
s <- "select * from TABLE WHERE COLUMN = 'value'"
result = dbGetQuery(con, s)
dbDisconnect(con)