我在R ed中有一个数据框我在带有JRI库的java类中读取它。我必须在java类中映射数据框中包含的数据。我想在json对象中转换数据框并构建他们的POJO但我需要帮助。有人可以帮帮我吗?我使用Eclipse Java EE IDE for Web Developers(版本:Luna Service Release 2(4.4.2))。谢谢!
这是我的R脚本名为" Rmongo.R:
library(rJava)
library(RMongo)
mongo <- mongoDbConnect("DBunical")
dbShowCollections(mongo)
results <- dbGetQuery(mongo, "Veicolo", '{}', 0, 3)
View(results)
结果是我的数据框架。
这是我的java类:
import org.rosuda.JRI.REXP;
import org.rosuda.JRI.Rengine;
public class rmongo {
public static void main(String[] args) {
System.out.println("Creating Rengine (with arguments)");
String[] Rargs = {"--vanilla"};
Rengine re = new Rengine(Rargs, false, null);
System.out.println("Rengine created, waiting for R");
// the engine creates R is a new thread, so we should wait until it's
// ready
if (!re.waitForR()) {
System.out.println("Cannot load R");
return;
}
System.out.println(re.eval(".libPaths(\"C:/Users/Stefania/Documents/R/win- library/3.2\")"));
System.out.println(re.eval(".libPaths()"));
re.eval("source(\"C:\\\\Rmongo.R\")");
}
}