| setJavaFunctionConverter {Java} | R Documentation |
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=T)
handler |
a function that takes two arguments: a reference to the Java object to be converted and the name of is Java class. This function should return the converted value or the reference to the Java object if it cannot convert it meaningfully. |
match |
a function that deterines whether the associated
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 textit{must} return a logical value
indicating whether the handler is capable of converting
the Java object. |
description |
a descripion that is stored internally with the converter
and accessible to users via the function getJavaConverterDescriptions. |
fromJava |
a logical value indicating whether the functions are intended for converting from Java to R or vice-versa. Currently, the R to Java mechanism is not implemented. |
An object of class texttt{"JavaFunctionConverter"} with fields
index |
the position of this converter in the internal list of converters. This is a useful identifier for removing the converter. |
description |
the value of the description argument.
This is also a useful and preferred identifier for removing the converter. |
handler |
the value of the handler argument. |
match |
the value of the match argument. |
The R to Java converter mechanism will be added in the next release.
Duncan Temple Lang
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", F)
removeJavaConverter(cvt$index)
}