简体   繁体   English

MonetDB在数据库中运行的R代码中连接到GO.db

[英]MonetDB connect to GO.db within R code that is run in-database

I am trying to run some R code in database. 我试图在数据库中运行一些R代码。 Most of it is going pretty well, but I seem to have stumbled on a bug. 大部分程序运行良好,但是我似乎偶然发现了一个错误。 I cannot load the following package, which is a dependency for some of my code. 我无法加载以下程序包,这是我的某些代码的依赖项。 WGCNA WGCNA

I have been chasing it down, and it seems to be due to an error when trying to load GO.db. 我一直在追逐它,这似乎是由于尝试加载GO.db时发生错误。

I get the following error: 我收到以下错误:

Error in .local(conn, statement, ...) : 
  Unable to execute statement 'SELECT * FROM tmp_test();'.
Server says '!Error running R expression. Error message: Error in as.data.frame((function() { : '.

Digging a bit further it seems to be due to the following statement: 进一步挖掘似乎是由于以下语句:

dbconn <- dbFileConnect(dbfile)

Error can be reproduced using: 可以使用以下方式重现错误:

functionDef <- paste(
"CREATE FUNCTION tmp_test() ",
"RETURNS TABLE(output STRING)",
"LANGUAGE R ",
"{", 
"library(AnnotationDbi)",
"datacache <- new.env(hash=TRUE, parent=emptyenv())",
"pkgname <- 'GO.db'",
"libname <- .libPaths()[1]",
"dbfile <- system.file('extdata', 'GO.sqlite', package=pkgname, lib.loc=libname)",
"assign('dbfile', dbfile, envir=datacache)",
"dbconn <- dbFileConnect(dbfile)",
"};", sep = "\n")

dbGetQuery(conn, functionDef)

dbGetQuery(conn, "SELECT * FROM tmp_test();")

By the way, installing GO.db from within MonetDB works just fine. 顺便说一句,从MonetDB中安装GO.db可以正常工作。 And can be done using the following R code: 并且可以使用以下R代码完成:

source("https://bioconductor.org/biocLite.R")
biocLite("GO.db")

Hints on how to resolve this are greatly appreciated. 非常感谢有关如何解决此问题的提示。

As to what datacache is supposed to do here, this was part of my debugging efforts. 至于数据缓存应该在这里做什么,这是我调试工作的一部分。 The code is part of zzz.R in the GO.db package. 该代码是GO.db软件包中zzz.R的一部分。 Another way to get this error is trying to load the GO.db package. 获取此错误的另一种方法是尝试加载GO.db程序包。

I tried the code from Hannes Mühleisen and I get the following result: I restarted monetdbd first. 我尝试了HannesMühleisen的代码,得到以下结果:我首先重新启动了monetdbd。

dbGetQuery(conn, "SELECT * FROM tmp_test()") QQ: 'SELECT * FROM tmp_test()' Error in .local(conn, statement, ...) : Unable to execute statement 'SELECT * FROM tmp_test()'. dbGetQuery(conn,“ SELECT * FROM tmp_test()”)QQ:'SELECT * FROM tmp_test()'.local(conn,statement,...)中的错误:无法执行语句'SELECT * FROM tmp_test()'。 Server says '!Error running R expression. 服务器说'!运行R表达式时出错。 Error message: Error in dbConnect(SQLite(), dbname = dbfile, cache_size = 64000, synchronous = "off", : '. 错误消息:dbConnect(SQLite(),dbname = dbfile,cache_size = 64000,synchronous =“ off”,:'中的错误。

Then I just tried again and got this error: 然后我再次尝试并得到此错误:

dbGetQuery(conn, "SELECT * FROM tmp_test()") QQ: 'SELECT * FROM tmp_test()' Error in .local(conn, statement, ...) : Unable to execute statement 'SELECT * FROM tmp_test()'. dbGetQuery(conn,“ SELECT * FROM tmp_test()”)QQ:'SELECT * FROM tmp_test()'.local(conn,statement,...)中的错误:无法执行语句'SELECT * FROM tmp_test()'。 Server says '!Error running R expression. 服务器说'!运行R表达式时出错。 Error message: Error in as.data.frame((function() { : '. 错误消息:as.data.frame((function(){:'。

After I restart monetdbd I can reproduce this cycle. 重新启动monetdbd之后,我可以重现此循环。

I got this to work as follows: First, I simplified the example code, removing the apparently unused datacache and using system.file instead of manually searching for the file name. 我按如下方式工作:首先,我简化了示例代码,删除了明显未使用的数据datacache并使用了system.file而不是手动搜索文件名。 Second, your function needs to actually return what you defined in the schema, in this case a STRING . 其次,您的函数需要实际返回您在模式中定义的内容,在本例中为STRING

functionDef <- "CREATE FUNCTION tmp_test() RETURNS TABLE(output STRING) LANGUAGE R {
  library(AnnotationDbi)
  dbfile <- system.file('extdata/GO.sqlite', package='GO.db')
  dbconn <- dbFileConnect(dbfile)
  return('Hello, World')
}"

Assuming the GO.db and AnnotationDbi packages are installed, this works fine for me: 假设安装了GO.db和AnnotationDbi软件包,这对我来说效果很好:

> dbGetQuery(conn, "SELECT * FROM tmp_test()")
        output
1 Hello, World

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM