RMySQL 包无法通过 JRI 接口加载
我已经成功地在 R 中安装了 RMySQL,并且它运行良好(我还安装了其所需的依赖项 DBI,并且它也运行良好)。我正在构建一个通过 JRI 包与 R 交互的 java 应用程序(也可以正常工作)。目前,我的应用程序查询 MySQL 数据库,将查询结果写入文件,然后在 R 中加载这些文件(通过使用 R 中的 load.csv() 函数)。然而,如果 R 直接与 MySQL 交互(因此有了 RMySQL 包),程序将运行得更高效。 我遇到的问题是,如果我尝试使用 Rengine.eval() JRI 函数加载 RMySQL 包,则它不会在 R 中加载。但是, Rengine.eval() 函数将加载我尝试加载的任何其他库。 下面是代码片段:
Rengine re;
re.eval("library(\"DBI\")"); // this works, DBI will load
re.eval("library(\"RMySQL\")"); // this will not work, RMySQL fails to load
为了验证 RMySQL 无法加载,我这样做了:
REXP x;
System.out.println(x=re.eval("library(\"DBI\")"));
System.out.println(x=re.eval("library(\"RMySQL\")"));
我得到以下输出:
[STRING* ("DBI", "stats", "graphics", "grDevices", "utils", " datasets", "methods", "base")]
null
可以清楚地看到,第二个 println 命令返回 null,这意味着 RMySQL 无法加载(当然 RMySQL 函数也不起作用)。我不知道为什么会这样。
我不知道我做错了什么,但如果有人能告诉我问题是什么,或者是否有更好的方法通过 JRI 加载库,我将非常感激。
请注意,我在 sparc-sun-solaris2.10 上使用 R 版本 2.13.0 和 RMySQL_0.8-0 版本。
I've managed to install RMySQL in R, and it runs fine (I also installed its required dependency, DBI, and it works fine too). I'm building a java application that interacts with R through the JRI package (which also works fine). Currently my application queries a MySQL database, writes the query results to file, and loads these files in R (by using the load.csv() function in R). However, the program would run more efficiently if R were to interact directly with MySQL (hence the RMySQL package).
The problem that I'm having is that the RMySQL package will not load in R if I try to load it by using the Rengine.eval() JRI function. However, the Rengine.eval() function will load any other library that I've tried loading.
Here's a snippet of the code:
Rengine re;
re.eval("library(\"DBI\")"); // this works, DBI will load
re.eval("library(\"RMySQL\")"); // this will not work, RMySQL fails to load
To verify that RMySQL is failing to load I did this:
REXP x;
System.out.println(x=re.eval("library(\"DBI\")"));
System.out.println(x=re.eval("library(\"RMySQL\")"));
I get the following output:
[STRING* ("DBI", "stats", "graphics", "grDevices", "utils", "datasets", "methods", "base")]
null
As can be clearly seen, the second println command is returning a null which means that the RMySQL is failing to load (and of course none of the RMySQL functions work either). I have no idea why this is the case.
I don't know what it is I'm doing wrong, but if someone can tell me what the problem is, or if there is a better way of loading libraries through JRI I would much appreciate it.
Note that I am using R version 2.13.0 on sparc-sun-solaris2.10, and the RMySQL_0.8-0 build.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
通过在运行 JRI 之前设置环境变量 R_HOME、R_INCLUDE_DIR、R_SHARE_DIR 和 R_DOC_DIR 解决了此问题。现在效果很好。
Resolved this issue by setting the environment variables R_HOME, R_INCLUDE_DIR, R_SHARE_DIR, and R_DOC_DIR before running JRI. Works now great.
我以前遇到过此类问题。
您可能以不正确的方式安装了 RMySQL 软件包,
例如,
正确的方法是:
在我安装了类型为“source”的包后,我成功通过JRI加载了包。
I had this type of problem before.
You probably installed RMySQL package not the correct way,
e.g.
The correct way will be:
I succeeded to load the package through JRI after i installed the package with type "source".