package rstatistics;
import rstatistics.interfaces.IRService;
import org.rosuda.JRI.Rengine;
/**
*
* @author vaio
*/
public final class RLocalConnector extends Singleton implements IRService {
private Rengine rConnection;
private RLocalConnector() {
rConnection = new Rengine(null, false, null);
if (!rConnection.waitForR()) {
System.out.println("Cannot load R");
return;
}
}
/**
*
* @return
*/
public static IRService getResource() {
if (resource == null) {
resource = new RLocalConnector();
}
return resource;
}
/**
*
* @param cmd
* @return
*/
@Override
public RExpressionLocal eval(String cmd) {
return new RExpressionLocal(rConnection.eval(cmd));
}
/**
*
* @param cmd
*/
@Override
public void voidEval(String cmd) {
rConnection.eval(cmd);
}
/**
*
* @return
*/
@Override
public boolean isConnected() {
return rConnection.isAlive();
}
/**
*
* @return
*/
@Override
public IRService getRService() {
return this;
}
}