[R] SJava convert problem

Slim Shady abu3ammar at gmail.com
Thu Dec 2 20:12:19 CET 2004


Consider this Java class:
class myClass {
    final public static String[] testString () {
        return new String[]{"my", "name", "is"} ;
    }
    
    final public static int[] testInt () {
        return new int[]{5, 10, 15};
    }    
    
    final public static char[] testChar () {
        return new char[]{'x', 'y', 'z'};
    }

}

When invoked in R:
> s <- .Java(className, "testString")
> class(s)
[1] "list"
> length(s)
[1] 3
> s
[[1]]
[1] "my"

[[2]]
[1] "name"

[[3]]
[1] "is"


> c <- .Java(className, "testChar")
> class(c)
[1] "character"
> length(c)
[1] 1
> c
[1] "X"

> i <- .Java(className, "testInt")
> class(i)
[1] "integer"
> length(i)
[1] 3
> i
[1]  5 10 15

Note that the conversion of testInt is just what I expected (and what
I get in S-PLUS). The conversion of testChar is flat wrong because
data is lost. The conversion of testString is problematic since I have
to convert the list back using as.character (in S-PLUS this function
returns character instaid of list and saves me the convertion from
list to character)
Is the convertion of char[] a bug? is there is a way to make the
conversion of String[] returns a character class instaid of a list
just like in the S-PLUS Java Connect?




More information about the R-help mailing list