
This allows one to register two functions that are used to convert an
object from Omegahat/Java to an R object. One function (match
)
determines whether the other function (handler
) that actually
performs the computation is suitable for converting the target object.
The result of the handler
function is an R object that
represents the Java object being converted.
setJavaFunctionConverter(handler, match, description=NULL, fromJava=TRUE, autoArray = TRUE, position = -1)
handler
function is appropriate for converting the target
Java object. This function should expect two arguments: a reference
to the Java object and its class name. It must return a
logical value indicating whether the handler
is capable of
converting the Java object.getJavaConverterDescriptions
.TRUE
)
or the array itself (FALSE
)."JavaFunctionConverter"
with fieldsdescription
argument. This
is also a useful and preferred identifier for removing the
converter.handler
argument.match
argument.setJavaConverter
setJavaConvertible
.Java
.JavaConstructor
# this must be run wit the ROmegahatExamples.jar
# file in the classpath (e.g.
# .JavaInit(list(classPath=system.file("org/omegahat/Jars/ROmegahatExamples.jar")))
# so as to be able to find RealVariable!
if(!is.null(.Java("__Evaluator", "expandClassName", "RealVariable"))) {
cvt <- setJavaFunctionConverter(function(jobj,className) {
.Java(jobj, "getValues")
}, function(jobj, className) {
return(className == "org.omegahat.DataStructures.Data.RealVariable")
}, "Omegahat RealVariable to numeric vector")
setJavaConvertible("RealVariable")
.JavaConstructor("RealVariable", rnorm(10))
# now unregister the converter
setJavaConvertible("RealVariable", FALSE)
removeJavaConverter(cvt$index)
}
Run the code above in your browser using DataLab