/** determines whether this object inherits from a given class in the same fashion as the <code>inherits()</code> function in R does (i.e. ignoring S4 inheritance) * @param klass class name * @return <code>true</code> if this object is of the class <code>klass</code>, <code>false</code> otherwise */ public boolean inherits(String klass) { if (!hasAttribute("class")) return false; try { String c[] = getAttribute("class").asStrings(); if (c != null) { int i = 0; while (i < c.length) { if (c[i]!=null && c[i].equals(klass)) return true; i++; } } } catch (REXPMismatchException me) { } return false; }
/** determines whether this object inherits from a given class in the same fashion as the <code>inherits()</code> function in R does (i.e. ignoring S4 inheritance) * @param klass class name * @return <code>true</code> if this object is of the class <code>klass</code>, <code>false</code> otherwise */ public boolean inherits(String klass) { if (!hasAttribute("class")) return false; try { String c[] = getAttribute("class").asStrings(); if (c != null) { int i = 0; while (i < c.length) { if (c[i]!=null && c[i].equals(klass)) return true; i++; } } } catch (REXPMismatchException me) { } return false; }
temp = new RDataFrame(this, rexp.getAttribute( RInstructions.ATTRIBUTE_NAMES).asStrings(), rexp.getAttribute(RInstructions.ATTRIBUTE_ROWNAMES).asStrings(), data, ""); return temp;
REXP attrNames = rexp.getAttribute(RInstructions.ATTRIBUTE_NAMES); String[] names = {}; if (attrNames!=null){
/** returns the content of the REXP as a matrix of doubles (2D-array: m[rows][cols]). This is the same form as used by popular math packages for Java, such as JAMA. This means that following leads to desired results:<br> <code>Matrix m=new Matrix(c.eval("matrix(c(1,2,3,4,5,6),2,3)").asDoubleMatrix());</code><br> @return 2D array of doubles in the form double[rows][cols] or <code>null</code> if the contents is no 2-dimensional matrix of doubles */ public double[][] asDoubleMatrix() throws REXPMismatchException { double[] ct = asDoubles(); REXP dim = getAttribute("dim"); if (dim == null) throw new REXPMismatchException(this, "matrix (dim attribute missing)"); int[] ds = dim.asIntegers(); if (ds.length != 2) throw new REXPMismatchException(this, "matrix (wrong dimensionality)"); int m = ds[0], n = ds[1]; double[][] r = new double[m][n]; // R stores matrices as matrix(c(1,2,3,4),2,2) = col1:(1,2), col2:(3,4) // we need to copy everything, since we create 2d array from 1d array int k = 0; for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) r[j][i] = ct[k++]; return r; }
/** returns the content of the REXP as a matrix of doubles (2D-array: m[rows][cols]). This is the same form as used by popular math packages for Java, such as JAMA. This means that following leads to desired results:<br> <code>Matrix m=new Matrix(c.eval("matrix(c(1,2,3,4,5,6),2,3)").asDoubleMatrix());</code> @return 2D array of doubles in the form double[rows][cols] or <code>null</code> if the contents is no 2-dimensional matrix of doubles */ public double[][] asDoubleMatrix() throws REXPMismatchException { double[] ct = asDoubles(); REXP dim = getAttribute("dim"); if (dim==null) throw new REXPMismatchException(this, "matrix (dim attribute missing)"); int[] ds = dim.asIntegers(); if (ds.length!=2) throw new REXPMismatchException(this, "matrix (wrong dimensionality)"); int m = ds[0], n = ds[1]; double[][] r=new double[m][n]; // R stores matrices as matrix(c(1,2,3,4),2,2) = col1:(1,2), col2:(3,4) // we need to copy everything, since we create 2d array from 1d array int i=0,k=0; while (i<n) { int j=0; while (j<m) { r[j++][i]=ct[k++]; } i++; } return r; }