These functions allow one to create multi-dimensional Java arrays via
R commands using the .Java function. The get and set
accessors work element-wise and not in the vector fashion common in R
and S. One must create and initialize the Java virtual machine before
calling any of these functions. See .JavaInit.
.JavaArrayConstructor(klass, ..., dim=length(list(...)), .name=NULL, .convert=FALSE)
.JavaGetArrayElement(jobj,..., .name=NULL, .convert=TRUE)
.JavaSetArrayElement(jobj, value, ..., .dims=list(...), .convert=FALSE)
.JavaArrayLength(jobj)
"["(x, ...)
"["(x, ...) <- value
"length"(x).Java..JavaArrayConstructor, these are currently
ignored. They are intended to be initializing values that are used
to populate the top-level values of the new array. That is, they
are used to set arr[0], arr[1], arr[2], .... In the JavaArrayReference methods these are indicies passed
to .JavaGetArrayElement and .JavaSetArrayElement.
.JavaArrayConstructor,
these specify both the number of dimensions and the length of each
dimension in the array to be created. .JavaSetArrayElement, a list of integer(1)
values corresponding to array dimensions of the element to be set..JavaArrayConstructor or the return value
from a call to .Java..Java calls.TRUE, but can be explicitly specified
to avoid (arrays of) primitive object being converted to an R object
when it is to be used in a subsequent .Java call..JavaArrayConstructor returns a reference to the newly create
Java array object..JavaArrayLength returns a single integer giving the length of
the top-level dimension of the array..JavaGetArrayElement returns the value of the specified element
of the given array, converted to an R object as usual. Thus it may be
a Java reference..JavaSetArrayElement returns NULL.
This uses the .Java to call methods in the Omegahat
Evaluator which process the array request.
.Java
if (!isJavaInitialized())
.JavaInit(verbose=TRUE)
a <- .JavaArrayConstructor("java.lang.String", dim=3)
.JavaArrayLength(a)
.JavaSetArrayElement(a, "First", 1)
.JavaSetArrayElement(a, "Second", 2)
.JavaSetArrayElement(a, "Third", 3)
.JavaGetArrayElement(a, 2)
Run the code above in your browser using DataLab