Learn R Programming

jdx (version 0.1.4)

jdx-package: Java Data Exchange for R and rJava

Description

Builds on rJava to simplify and extend data exchange between R and Java.

Arguments

Details

The jdx package works in conjunction with rJava to provide a low-level interface for the Java platform. The jdx package was originally developed to provide data exchange functionality for jsr223, the high-level scripting interface for the Java platform. We provide jdx to developers who may want to extend existing rJava solutions. For developers of new applications, we suggest the jsr223 package for rapid application development with a relatively low learning curve.

The jdx package converts R data structures to generic Java objects and vice versa. In particular, R vectors, n-dimensional arrays, factors, data frames, tables, environments, and lists are converted to Java objects. Java scalars and n-dimensional arrays are converted to R vectors and n-dimensional arrays. Java maps and collections are converted to R lists, data frames, vectors, or n-dimensional arrays depending on content. Several options are available for data conversion including row-major and column-major ordering for arrays and data frames.

For sites that plan on designing and distributing packages that depend on jdx, it may be helpful to know that the jdx package does not use or load rJava's companion package JRI (the Java/R Interface).

For best results, please refer to the vignette Introduction to jdx: Java Data Exchange for R and rJava.

See Also

convertToJava , convertToR , getJavaClassName

Examples

Run this code
# NOT RUN {
library("jdx")

# Convert matrix using column-major ordering
m <- matrix(1:4, 2, 2)
o = convertToJava(m, array.order = "column-major")
getJavaClassName(o)
identical(m, convertToR(o, array.order = "column-major"))

# Convert 4-dimensional array using row-major ordering
dimensions <- c(3, 2, 2, 2)
a = array(1:prod(dimensions), dimensions)
o = convertToJava(a, array.order = "row-major")
getJavaClassName(o)
identical(a, convertToR(o, array.order = "row-major"))

# Convert data frame
identical(iris, convertToR(convertToJava(iris)))

# Demonstrate exact double precision
identical(pi, convertToR(convertToJava(pi, scalars.as.objects = TRUE)))
# }

Run the code above in your browser using DataLab