如何利用r语言和java来做web应用分析

Python012

如何利用r语言和java来做web应用分析,第1张

展开全部

Java调用R,就是使用JRI.jar中的Api,执行一条R语言命令,当然首先你要了解R语言的语法。

1.JRI中主要的API

Rengine

R引擎,通过它进行R语言的启动、运算、画图、关闭等功能。

一个线程只能实例化一次,推荐使用单例模式。

如果调用第三方jar包的资源文件,在制作jar包和告诉别人如何调用你的jar包时经常用到。通常有两种方法,具体如下:

1)在应用程序端访问第三方jar包里面的raw文件,方法如下:

InputStream

is=org.hisense.facerecog.R.class.getResourceAsStream("data.xml")

File cascadeDir = this.getDir("cas",

Context.MODE_PRIVATE)

mCascadeFile = new File(casDir,

"data.xml")

FileOutputStream os = new

FileOutputStream(mCascadeFile)

其中org.hisense.facerecog.R为jar包中资源文件R.java的路径,this为当前应用程序环境。

2)在第三方jar包中直接访问其资源文件,将其拷贝到应用程序端,需要给出应用程序环境:Context

context

方法如下:

InputStream is =

this.getClass().getResourceAsStream("/res/raw/ data .xml")

File cascadeDir = context.getDir("cas",

Context.MODE_PRIVATE)

mCascadeFile = new File(casDir,

" data.xml")

FileOutputStream os = new

FileOutputStream(mCascadeFile)

其中this为第三方jar中的类运行环境,context为应用程序环境。

两中方法最后都会在应用程序根目录下生成cas/data.xml文件,对应于第三方jar包中的/res/raw/data.txt文件