Package ubic.basecode.util.r
Class AbstractRClient
java.lang.Object
ubic.basecode.util.r.AbstractRClient
- All Implemented Interfaces:
RClient
- Direct Known Subclasses:
JRIClient
,RServeClient
Base class for RClients
- Author:
- Paul
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionassignFactor
(String factorName, List<String> list) assignFactor
(List<String> strings) assignMatrix
(double[][] matrix) Assign a 2-d matrix.assignMatrix
(DoubleMatrix<?, ?> matrix) Assign a 2-d matrix.assignMatrix
(DoubleMatrix<?, ?> matrix, org.apache.commons.collections4.Transformer rowNameExtractor) Assign a 2-d matrix.assignStringList
(List<?> strings) Define a variable corresponding to a character array in the R context, given a List of Strings.boolean
booleanDoubleArrayEval
(String command, String argName, double[] arg) Run a command that takes a double array as an argument and returns a boolean.dataFrame
(ObjectMatrix<String, String, Object> matrix) Convert an object matrix into an R data frame.dataFrameEval
(String command) Evaluate a command that returns a dataFrameabstract void
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.double
doubleTwoDoubleArrayEval
(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) linearModel
(double[] data, Map<String, List<?>> factors) Lower level access to linear model.linearModel
(double[] data, ObjectMatrix<String, String, Object> d) List
<?> FIXME only partly implemented, possibly not going to stay.boolean
loadLibrary
(String libraryName) protected void
There is a pretty annoying limitation of this.oneWayAnova
(double[] data, List<String> factor) Lower-level access to a simple one-way ANOVAoneWayAnovaEval
(String command) void
Remove a variable from the R namespacerowApplyLinearModel
(String dataMatrixVarName, String modelFormula, String[] factorNames) Run lm with anova on all the rows of a matrixstringEval
(String command) Evaluate any command and return a stringstringListEval
(String command) twoWayAnova
(double[] data, List<String> factor1, List<String> factor2, boolean includeInteraction) Lower-level access to two-way ANOVAtwoWayAnovaEval
(String command, boolean withInteractions) Evaluates two way anova commands of the formstatic String
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
-
Field Details
-
log
protected static org.slf4j.Logger log
-
-
Constructor Details
-
AbstractRClient
public AbstractRClient()
-
-
Method Details
-
variableIdentityNumber
- Parameters:
ob
-- Returns:
-
assignFactor
- Specified by:
assignFactor
in interfaceRClient
- Parameters:
strings
-- Returns:
- the name of the factor generated.
-
assignFactor
- Specified by:
assignFactor
in interfaceRClient
- Parameters:
factorName
-list
-- Returns:
- the factor name
-
assignMatrix
Description copied from interface:RClient
Assign a 2-d matrix.- Specified by:
assignMatrix
in interfaceRClient
- Parameters:
matrix
-- Returns:
- the name of the variable by which the R matrix can be referred.
-
assignMatrix
Description copied from interface:RClient
Assign a 2-d matrix.- Specified by:
assignMatrix
in interfaceRClient
- Parameters:
matrix
-- 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:RClient
Assign a 2-d matrix.- Specified by:
assignMatrix
in interfaceRClient
- Parameters:
matrix
-rowNameExtractor
-- Returns:
- the name of the variable by which the R matrix can be referred.
-
assignStringList
Description copied from interface:RClient
Define a variable corresponding to a character array in the R context, given a List of Strings.- Specified by:
assignStringList
in interfaceRClient
- Parameters:
strings
- , which will be stringified if they are not strings.- Returns:
- the name of the variable in the R context.
-
booleanDoubleArrayEval
Description copied from interface:RClient
Run a command that takes a double array as an argument and returns a boolean.- Specified by:
booleanDoubleArrayEval
in interfaceRClient
- Parameters:
command
-argName
-arg
-- Returns:
-
dataFrame
Description copied from interface:RClient
Convert an object matrix into an R data frame. Columns that look numeric are treated as numbers. Booleans and Strings are treated as factors. -
dataFrameEval
Description copied from interface:RClient
Evaluate a command that returns a dataFrame- Specified by:
dataFrameEval
in interfaceRClient
- Parameters:
command
-- Returns:
- an ObjectMatrix representation of the data frame.
-
disconnect
public abstract void disconnect() -
doubleArrayDoubleArrayEval
Description copied from interface:RClient
Run a command that has a single double array parameter, and returns a double array.- Specified by:
doubleArrayDoubleArrayEval
in interfaceRClient
- Parameters:
command
-argName
-arg
-- Returns:
-
doubleArrayEval
Description copied from interface:RClient
Run a command that returns a double array with no arguments.- Specified by:
doubleArrayEval
in interfaceRClient
- Parameters:
command
-- Returns:
-
doubleArrayTwoDoubleArrayEval
public double[] doubleArrayTwoDoubleArrayEval(String command, String argName, double[] arg, String argName2, double[] arg2) Description copied from interface:RClient
Run a command that takes two double array arguments and returns a double array.- Specified by:
doubleArrayTwoDoubleArrayEval
in interfaceRClient
- Parameters:
command
-argName
-arg
-argName2
-arg2
-- Returns:
-
doubleTwoDoubleArrayEval
public double doubleTwoDoubleArrayEval(String command, String argName, double[] arg, String argName2, double[] arg2) Description copied from interface:RClient
Run a command that takes two double arrays as arguments and returns a double value.- Specified by:
doubleTwoDoubleArrayEval
in interfaceRClient
- Parameters:
command
-argName
-arg
-argName2
-arg2
-- Returns:
-
intArrayEval
- Specified by:
intArrayEval
in interfaceRClient
-
linearModel
Description copied from interface:RClient
Lower level access to linear model. Fairly simple. Factors are assigned in turn.- Specified by:
linearModel
in interfaceRClient
- Parameters:
data
-factors
- 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
- Specified by:
linearModel
in interfaceRClient
- Parameters:
data
-d
- 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
FIXME only partly implemented, possibly not going to stay. -
loadLibrary
- Specified by:
loadLibrary
in interfaceRClient
-
oneWayAnova
Description copied from interface:RClient
Lower-level access to a simple one-way ANOVA- Specified by:
oneWayAnova
in interfaceRClient
- Parameters:
data
-factor
-- Returns:
-
oneWayAnovaEval
- Specified by:
oneWayAnovaEval
in interfaceRClient
-
remove
Description copied from interface:RClient
Remove a variable from the R namespace -
rowApplyLinearModel
public Map<String,LinearModelSummary> rowApplyLinearModel(String dataMatrixVarName, String modelFormula, String[] factorNames) Description copied from interface:RClient
Run lm with anova on all the rows of a matrix- Specified by:
rowApplyLinearModel
in 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
Description copied from interface:RClient
Evaluate any command and return a string- Specified by:
stringEval
in interfaceRClient
- Parameters:
command
-- Returns:
- string
-
stringListEval
- Specified by:
stringListEval
in interfaceRClient
-
twoWayAnova
public TwoWayAnovaResult twoWayAnova(double[] data, List<String> factor1, List<String> factor2, boolean includeInteraction) Description copied from interface:RClient
Lower-level access to two-way ANOVA- Specified by:
twoWayAnova
in interfaceRClient
- Parameters:
data
-factor1
-factor2
-includeInteraction
-- Returns:
- result with interaction term information null if includeInteraction = false
-
twoWayAnovaEval
Description copied from interface:RClient
Evaluates 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:
twoWayAnovaEval
in interfaceRClient
- Parameters:
command
-- Returns:
-
loadScript
There is a pretty annoying limitation of this. The file must contain only one statement. You can get around this by using c(xinvalid input: '<'-1,xinvalid input: '<'-2). See testScript.R- Parameters:
is
-
-