for (Enumeration e = v.getNames().elements() ; e.hasMoreElements() ;) {
System.out.println(e.nextElement());
}
}
// for compatibility with Rserve we allow casting of vectors to lists
RList vl = x.asList();
String[] k = vl.keys();
if (k!=null) {
System.out.println("and once again from the list:");
int i=0; while (i<k.length) System.out.println(k[i++]);
}
// get boolean array
System.out.println(x=re.eval("iris[[1]]>mean(iris[[1]])"));
// R knows about TRUE/FALSE/NA, so we cannot use boolean[] this way
// instead, we use int[] which is more convenient (and what R uses internally anyway)
int[] bi = x.asIntArray();
{
int i = 0; while (i<bi.length) { System.out.print(bi[i]==0?"F ":(bi[i]==1?"T ":"NA ")); i++; }
System.out.println("");
}
// push a boolean array
boolean by[] = { true, false, false };
re.assign("bool", by);
System.out.println(x=re.eval("bool"));
// asBool returns the first element of the array as RBool
// (mostly useful for boolean arrays of the length 1). is should return true
System.out.println("isTRUE? "+x.asBool().isTRUE());
// now for a real dotted-pair list:
System.out.println(x=re.eval("pairlist(a=1,b='foo',c=1:5)"));
RList l = x.asList();
if (l!=null) {
int i=0;
String [] a = l.keys();
System.out.println("Keys:");
while (i<a.length) System.out.println(a[i++]);
System.out.println("Contents:");
i=0;
while (i<a.length) System.out.println(l.at(i++));
}
System.out.println(re.eval("sqrt(36)"));
} catch (Exception e) {
System.out.println("EX:"+e);
e.printStackTrace();