Description Usage Arguments Details See Also Examples
The functions listed here are the low-level interface for jdx and are primarily used behind the scenes in jsr223, the high-level integration package for Java. However, these functions may also be useful for rJava developers interested in a thread-safe alternative to convertToR
. See the code examples for a brief outline. If multi-threaded access is not required, please use convertToR
.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | arrayOrderToString(value)
convertToRlowLevel(
j2r,
data.code = NULL,
strings.as.factors = NULL
)
createJavaToRobject()
jdxConstants()
processCompositeDataCode(
j2r,
composite.data.code,
throw.exceptions = TRUE,
warn.missing.logical = TRUE,
warn.missing.raw = TRUE
)
|
value |
An rJava object reference to a |
j2r |
An rJava object reference to a |
data.code |
A jdx data code value created with |
strings.as.factors |
Same as in |
composite.data.code |
A jdx composite data code returned by the |
throw.exceptions |
A logical value indicating whether to throw exceptions. |
warn.missing.logical |
A logical value indicating whether to raise a specific warning. |
warn.missing.raw |
A logical value indicating whether to raise a specific warning. |
See the code examples below for a thread-safe alternative to convertToR
. The low-level functional interface presented here is awkward, but it was designed to limit type inference and the number of transactions between R and the JVM, ultimately maximizing performance for jsr223.
convertToJava
, convertToR
, getJavaClassName
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | library("jdx")
# Create org.fgilbert.jdx.JavaToR object used to convert
# java objects to R objects. Create one of these objects
# per thread for thread-safe execution.
#
# It is also possible to create and use the JavaToR
# object in Java and return a reference to R via rJava.
j2r <- createJavaToRobject()
# Pass the Java object to be converted to the initialize
# method of the JavaToR object. Note that the Java object
# must be cast as java.lang.Object. The initialize method
# returns an integer value known as a composite data code
# that is used to derive the R structure.
composite.data.code <- rJava::.jcall(
j2r
, "I"
, "initialize"
, rJava::.jcast(convertToJava(iris))
)
# Process the resulting composite data code to get a data
# code vector. This step also raises any applicable
# errors/warnings.
data.code <- processCompositeDataCode(j2r, composite.data.code)
# Pass the JavaToR object and the data code to
# convertToRlowLevel to get the R object.
convertToRlowLevel(j2r, data.code, strings.as.factors = FALSE)
# When converting n-dimensional arrays, pass an array
# ordering constant to the initialize method.
array.order.constants <- jdxConstants()$ARRAY_ORDER
array <- convertToJava(as.matrix(iris[1:4]), array.order = "column-major")
composite.data.code <- rJava::.jcall(
j2r
, "I"
, "initialize"
, rJava::.jcast(array)
, array.order.constants[["column-major"]]
)
data.code <- processCompositeDataCode(j2r, composite.data.code)
convertToRlowLevel(j2r, data.code)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.