package rstatistics;
import rstatistics.interfaces.IRExpression;
import org.rosuda.JRI.REXP;
import org.rosuda.JRI.RVector;
/**
*
* @author vaio
*/
public class RExpressionLocal extends REXP implements IRExpression {
private REXP rexp;
/**
*
* @param rexp
*/
public RExpressionLocal(REXP rexp) {
this.rexp = rexp;
}
@Override
public String[] asStrings() {
return rexp.asStringArray();
}
/**
*
* @return
*/
@Override
public double[][] asDoubleMatrix() {
return rexp.asDoubleMatrix();
}
@Override
public double asDouble() {
return rexp.asDouble();
}
@Override
public double[] asDoubles() {
return rexp.asDoubleArray();
}
@Override
public String asString() {
return rexp.asString();
}
@Override
public double[][] asDoublesMatrix() {
if (rexp == null) {
return null;
}
RVector vetor = rexp.asVector();
if (vetor == null) {
return null;
}
REXP r = (REXP) vetor.get(0);
double[][] ret = new double[vetor.size()][((double[]) r.getContent()).length];
for (int col = 0; col < ret.length; col++) {
REXP coluna = (REXP) vetor.get(col);
for (int lin = 0; lin < ret[col].length; lin++) {
ret[col][lin] = ((double[]) coluna.getContent())[lin];
}
}
return ret;
}
}