jdx-package: Java Data Exchange for R and rJava

Description Details Author(s) See Also Examples

Description

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

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.

Author(s)

Floid R. Gilbert floid.r.gilbert@gmail.com, David B. Dahl dahl@stat.byu.edu

See Also

convertToJava , convertToR , getJavaClassName

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
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)))

Example output

[1] "[[I"
[1] TRUE
[1] "[[[[I"
[1] TRUE
[1] FALSE
[1] TRUE

jdx documentation built on July 2, 2020, 2:12 a.m.