[R] SJava converter

Slim Shady abu3ammar at gmail.com
Thu Dec 2 17:37:57 CET 2004


public static Object myMethod () {
   ...
      Object obj = null;
      if () { obj = new String [size] ; }
      else { obj = new double [size]; }
   ...
  System.out.println("in java");
  return obj;
}

This Java function returns String[] or Double[]. 

This is how I call the function from my R code.  
data <- .Java(myClass, "myMethod")
print("out of java")

When the function returns Double[] the conversion between Java and R
happens quickly. I am measuring the convertion time by how long it
takes between printing "in java" and "out of java". When teh returned
is String[] the conversion takes too long and in some cases where size
is large (150,000 for Strings of 10 chars each) the JVM runs out of
memory. Can I solve this by implementing my own converter? is there an
obvious reason why the default conversion for String[] is too slow and
runs out of memory?
These are my current converters:
> getJavaConverterDescriptions()
$fromJava
 [1] "From Java java.util.Vector to R list/vector"          
 [2] "org.omegahat.Environment.Utils.OrderedTable from Java"
 [3] "From Java 1-D array to R list/vector"                 
 [4] "Converts any Java InterfaceReference"                 
 [5] "class == java.lang.reflect.Method"                    
 [6] "class == java.lang.reflect.Constructor"               
 [7] "instanceof java.util.Properties"                      
 [8] "Integer[]"                                            
 [9] "Double[]"                                             
[10] "Boolean[]"                                            
[11] "[[<primitive> to a list of built-in vectors"          

$toJava
[1] "list object to Java"                  
[2] "org/omegahat/R/Java/RFunctionListener"




More information about the R-help mailing list