Learn R Programming

Runiversal (version 1.0.2)

makejava: A wrapper function for converting R objects to Java style variables.

Description

This function converts R objects to Java arrays. If R object is numeric than the Java object is double[]. Otherwise the Java object will be String[].

Usage

makejava(obj, name = "")

Arguments

obj
R object that to be converted to Java style variables.
name
New variable name for created Java style variable. If R object is only a vector, a name have to be given. If R object is a list, name is inoperative.

Value

Returns interpretable code for Bean Shell and Java of R objects.

Details

This function returns interpretable code for most frequently used dynamic Java interpreters such as Bean Shell. So this function can be used for using R codes in Java without JNI. This is an inefficient way to use R in Java but implementation is quite easy and platform independent.

References

See an Java implementation using this functionality in http://www.mhsatman.com/rcaller.php

See Also

makexml

Examples

Run this code
#Shows the linear regression results as Java style variables
y<-rnorm(10)
x<-1:10
ols<-lm(y~x)
cat(makejava(ols))

#Shows only the residuals as double[] Residuals=new double[]{.....};
cat(makejava(ols$residuals, "Residuals"))


Run the code above in your browser using DataLab