Package ubic.basecode.util.r
Class AbstractRClient
- java.lang.Object
-
- ubic.basecode.util.r.AbstractRClient
-
- All Implemented Interfaces:
RClient
- Direct Known Subclasses:
JRIClient,RServeClient
public abstract class AbstractRClient extends Object implements RClient
Base class for RClients- Author:
- Paul
-
-
Field Summary
Fields Modifier and Type Field Description protected static org.slf4j.Loggerlog
-
Constructor Summary
Constructors Constructor Description AbstractRClient()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description StringassignFactor(String factorName, List<String> list)StringassignFactor(List<String> strings)StringassignMatrix(double[][] matrix)Assign a 2-d matrix.StringassignMatrix(DoubleMatrix<?,?> matrix)Assign a 2-d matrix.StringassignMatrix(DoubleMatrix<?,?> matrix, org.apache.commons.collections4.Transformer rowNameExtractor)Assign a 2-d matrix.StringassignStringList(List<?> strings)Define a variable corresponding to a character array in the R context, given a List of Strings.booleanbooleanDoubleArrayEval(String command, String argName, double[] arg)Run a command that takes a double array as an argument and returns a boolean.StringdataFrame(ObjectMatrix<String,String,Object> matrix)Convert an object matrix into an R data frame.ObjectMatrix<String,String,Object>dataFrameEval(String command)Evaluate a command that returns a dataFrameabstract voiddisconnect()double[]doubleArrayDoubleArrayEval(String command, String argName, double[] arg)Run a command that has a single double array parameter, and returns a double array.double[]doubleArrayEval(String command)Run a command that returns a double array with no arguments.double[]doubleArrayTwoDoubleArrayEval(String command, String argName, double[] arg, String argName2, double[] arg2)Run a command that takes two double array arguments and returns a double array.doubledoubleTwoDoubleArrayEval(String command, String argName, double[] arg, String argName2, double[] arg2)Run a command that takes two double arrays as arguments and returns a double value.int[]intArrayEval(String command)LinearModelSummarylinearModel(double[] data, Map<String,List<?>> factors)Lower level access to linear model.LinearModelSummarylinearModel(double[] data, ObjectMatrix<String,String,Object> d)List<?>listEval(Class<?> listEntryType, String command)FIXME only partly implemented, possibly not going to stay.booleanloadLibrary(String libraryName)protected voidloadScript(InputStream is)There is a pretty annoying limitation of this.OneWayAnovaResultoneWayAnova(double[] data, List<String> factor)Lower-level access to a simple one-way ANOVAMap<String,OneWayAnovaResult>oneWayAnovaEval(String command)voidremove(String variableName)Remove a variable from the R namespaceMap<String,LinearModelSummary>rowApplyLinearModel(String dataMatrixVarName, String modelFormula, String[] factorNames)Run lm with anova on all the rows of a matrixStringstringEval(String command)Evaluate any command and return a stringList<String>stringListEval(String command)TwoWayAnovaResulttwoWayAnova(double[] data, List<String> factor1, List<String> factor2, boolean includeInteraction)Lower-level access to two-way ANOVAMap<String,TwoWayAnovaResult>twoWayAnovaEval(String command, boolean withInteractions)Evaluates two way anova commands of the formstatic StringvariableIdentityNumber(Object ob)-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface ubic.basecode.util.r.RClient
assign, assign, assign, assign, eval, getLastError, isConnected, retrieveMatrix, voidEval
-
-
-
-
Method Detail
-
variableIdentityNumber
public static String variableIdentityNumber(Object ob)
- Parameters:
ob-- Returns:
-
assignFactor
public String assignFactor(List<String> strings)
- Specified by:
assignFactorin interfaceRClient- Returns:
- the name of the factor generated.
-
assignFactor
public String assignFactor(String factorName, List<String> list)
- Specified by:
assignFactorin interfaceRClient- Returns:
- the factor name
-
assignMatrix
public String assignMatrix(double[][] matrix)
Description copied from interface:RClientAssign a 2-d matrix.- Specified by:
assignMatrixin interfaceRClient- Returns:
- the name of the variable by which the R matrix can be referred.
-
assignMatrix
public String assignMatrix(DoubleMatrix<?,?> matrix)
Description copied from interface:RClientAssign a 2-d matrix.- Specified by:
assignMatrixin interfaceRClient- Returns:
- the name of the variable by which the R matrix can be referred.
-
assignMatrix
public String assignMatrix(DoubleMatrix<?,?> matrix, org.apache.commons.collections4.Transformer rowNameExtractor)
Description copied from interface:RClientAssign a 2-d matrix.- Specified by:
assignMatrixin interfaceRClient- Returns:
- the name of the variable by which the R matrix can be referred.
-
assignStringList
public String assignStringList(List<?> strings)
Description copied from interface:RClientDefine a variable corresponding to a character array in the R context, given a List of Strings.- Specified by:
assignStringListin interfaceRClient- Parameters:
strings- , which will be stringified if they are not strings.- Returns:
- the name of the variable in the R context.
-
booleanDoubleArrayEval
public boolean booleanDoubleArrayEval(String command, String argName, double[] arg)
Description copied from interface:RClientRun a command that takes a double array as an argument and returns a boolean.- Specified by:
booleanDoubleArrayEvalin interfaceRClient- Returns:
-
dataFrame
public String dataFrame(ObjectMatrix<String,String,Object> matrix)
Description copied from interface:RClientConvert an object matrix into an R data frame. Columns that look numeric are treated as numbers. Booleans and Strings are treated as factors.
-
dataFrameEval
public ObjectMatrix<String,String,Object> dataFrameEval(String command)
Description copied from interface:RClientEvaluate a command that returns a dataFrame- Specified by:
dataFrameEvalin interfaceRClient- Returns:
- an ObjectMatrix representation of the data frame.
-
disconnect
public abstract void disconnect()
-
doubleArrayDoubleArrayEval
public double[] doubleArrayDoubleArrayEval(String command, String argName, double[] arg)
Description copied from interface:RClientRun a command that has a single double array parameter, and returns a double array.- Specified by:
doubleArrayDoubleArrayEvalin interfaceRClient- Returns:
-
doubleArrayEval
public double[] doubleArrayEval(String command)
Description copied from interface:RClientRun a command that returns a double array with no arguments.- Specified by:
doubleArrayEvalin interfaceRClient- Returns:
-
doubleArrayTwoDoubleArrayEval
public double[] doubleArrayTwoDoubleArrayEval(String command, String argName, double[] arg, String argName2, double[] arg2)
Description copied from interface:RClientRun a command that takes two double array arguments and returns a double array.- Specified by:
doubleArrayTwoDoubleArrayEvalin interfaceRClient- Returns:
-
doubleTwoDoubleArrayEval
public double doubleTwoDoubleArrayEval(String command, String argName, double[] arg, String argName2, double[] arg2)
Description copied from interface:RClientRun a command that takes two double arrays as arguments and returns a double value.- Specified by:
doubleTwoDoubleArrayEvalin interfaceRClient- Returns:
-
intArrayEval
public int[] intArrayEval(String command)
- Specified by:
intArrayEvalin interfaceRClient
-
linearModel
public LinearModelSummary linearModel(double[] data, Map<String,List<?>> factors)
Description copied from interface:RClientLower level access to linear model. Fairly simple. Factors are assigned in turn.- Specified by:
linearModelin interfaceRClientfactors- Map of factorNames to factors (which can be expressed as Strings or Doubles). If you care about the order the factors are introduced into the model, use a LinkedHashMap.
-
linearModel
public LinearModelSummary linearModel(double[] data, ObjectMatrix<String,String,Object> d)
- Specified by:
linearModelin interfaceRClientd- which will be converted to factors or continuous covariates depending on whether the columns are booleans, strings or numerical. Names of factors are the column names of the design matrix, and the rows are assumed to be in the same order as the data.- Returns:
-
listEval
public List<?> listEval(Class<?> listEntryType, String command)
FIXME only partly implemented, possibly not going to stay.
-
loadLibrary
public boolean loadLibrary(String libraryName)
- Specified by:
loadLibraryin interfaceRClient
-
oneWayAnova
public OneWayAnovaResult oneWayAnova(double[] data, List<String> factor)
Description copied from interface:RClientLower-level access to a simple one-way ANOVA- Specified by:
oneWayAnovain interfaceRClient- Returns:
-
oneWayAnovaEval
public Map<String,OneWayAnovaResult> oneWayAnovaEval(String command)
- Specified by:
oneWayAnovaEvalin interfaceRClient
-
remove
public void remove(String variableName)
Description copied from interface:RClientRemove a variable from the R namespace
-
rowApplyLinearModel
public Map<String,LinearModelSummary> rowApplyLinearModel(String dataMatrixVarName, String modelFormula, String[] factorNames)
Description copied from interface:RClientRun lm with anova on all the rows of a matrix- Specified by:
rowApplyLinearModelin interfaceRClient- Parameters:
dataMatrixVarName- from an assignment of a matrixmodelFormula- and other options that will be passed as the argument to 'lm(...)', that refers to factor variables that have already been assigned, using x as the outcome. Example might be x ~ f1 + f2.- Returns:
- map of row identifiers to populated LinearModelSummaries.
-
stringEval
public String stringEval(String command)
Description copied from interface:RClientEvaluate any command and return a string- Specified by:
stringEvalin interfaceRClient- Returns:
- string
-
stringListEval
public List<String> stringListEval(String command)
- Specified by:
stringListEvalin interfaceRClient
-
twoWayAnova
public TwoWayAnovaResult twoWayAnova(double[] data, List<String> factor1, List<String> factor2, boolean includeInteraction)
Description copied from interface:RClientLower-level access to two-way ANOVA- Specified by:
twoWayAnovain interfaceRClient- Returns:
- result with interaction term information null if includeInteraction = false
-
twoWayAnovaEval
public Map<String,TwoWayAnovaResult> twoWayAnovaEval(String command, boolean withInteractions)
Description copied from interface:RClientEvaluates two way anova commands of the formapply(matrix,1,function(x){anova(aov(x~farea+ftreat))}
andapply(matrix,1,function(x){anova(aov(x~farea+ftreat+farea*ftreat))}
where farea and ftreat have already been transposed and had factor called on them.- Specified by:
twoWayAnovaEvalin interfaceRClient- Returns:
-
loadScript
protected void loadScript(InputStream is)
There is a pretty annoying limitation of this. The file must contain only one statement. You can get around this by using c(x<-1,x<-2). See testScript.R- Parameters:
is-
-
-