Description Usage Arguments Value Note Author(s) References See Also Examples
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.
1 2 | setJavaFunctionConverter(handler, match, description=NULL, fromJava=TRUE,
autoArray = TRUE, position = -1)
|
handler |
a function that takes two arguments: a reference to the Java object to be converted and the name of its 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
|
description |
a descripion that is stored internally with the converter
and accessible to users via the function
|
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. |
autoArray |
a logical value indicating whether R is to deal with
Java arrays in relation to this converter by calling the
match/predicate function with an element of the array ( |
position |
the index (starting at 1) at which to insert the converter. If this is non-positive, the converter entry is appended at the end of the list. |
An object of class "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 |
handler |
the value of the |
match |
the value of the |
The R to Java converter mechanism will be added in the next release.
Duncan Temple Lang
http://www.omegahat.org/RSJava/index.html
setJavaConverter
setJavaConvertible
.Java
.JavaConstructor
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | # 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)
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.