Package ubic.basecode.util.r
Interface RClient
-
- All Known Implementing Classes:
AbstractRClient
,JRIClient
,RServeClient
public interface RClient
Abstraction of a connection to R- Author:
- Paul
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description void
assign(String argName, double[] arg)
void
assign(String arg0, int[] arg1)
void
assign(String sym, String ct)
void
assign(String argName, String[] array)
String
assignFactor(String factorName, List<String> list)
String
assignFactor(List<String> strings)
String
assignMatrix(double[][] matrix)
Assign a 2-d matrix.String
assignMatrix(DoubleMatrix<?,?> matrix)
Assign a 2-d matrix.String
assignMatrix(DoubleMatrix<?,?> matrix, org.apache.commons.collections4.Transformer rowNameExtractor)
Assign a 2-d matrix.String
assignStringList(List<?> objects)
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.String
dataFrame(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 dataFramedouble[]
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.org.rosuda.REngine.REXP
eval(String command)
Evaluate the given commandString
getLastError()
int[]
intArrayEval(String command)
boolean
isConnected()
LinearModelSummary
linearModel(double[] data, Map<String,List<?>> factors)
Lower level access to linear model.LinearModelSummary
linearModel(double[] data, ObjectMatrix<String,String,Object> design)
List<?>
listEval(Class<?> listEntryType, String command)
boolean
loadLibrary(String libraryName)
OneWayAnovaResult
oneWayAnova(double[] data, List<String> factor)
Lower-level access to a simple one-way ANOVAMap<String,OneWayAnovaResult>
oneWayAnovaEval(String command)
void
remove(String variableName)
Remove a variable from the R namespaceDoubleMatrix<String,String>
retrieveMatrix(String variableName)
Get a matrix back out of the R context.Map<String,LinearModelSummary>
rowApplyLinearModel(String dataMatrixVarName, String modelFormula, String[] factorNames)
Run lm with anova on all the rows of a matrixString
stringEval(String command)
Evaluate any command and return a stringList<String>
stringListEval(String command)
TwoWayAnovaResult
twoWayAnova(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 formvoid
voidEval(String command)
-
-
-
Method Detail
-
assign
void assign(String argName, double[] arg)
- Parameters:
argName
-arg
-
-
assign
void assign(String arg0, int[] arg1)
-
assignFactor
String assignFactor(List<String> strings)
- Parameters:
strings
-- Returns:
- the name of the factor generated.
-
assignFactor
String assignFactor(String factorName, List<String> list)
- Parameters:
factorName
-list
-- Returns:
- the factor name
-
assignMatrix
String assignMatrix(double[][] matrix)
Assign a 2-d matrix.- Parameters:
matrix
-- Returns:
- the name of the variable by which the R matrix can be referred.
-
assignMatrix
String assignMatrix(DoubleMatrix<?,?> matrix)
Assign a 2-d matrix.- Parameters:
matrix
-- Returns:
- the name of the variable by which the R matrix can be referred.
-
assignMatrix
String assignMatrix(DoubleMatrix<?,?> matrix, org.apache.commons.collections4.Transformer rowNameExtractor)
Assign a 2-d matrix.- Parameters:
matrix
-rowNameExtractor
-- Returns:
- the name of the variable by which the R matrix can be referred.
-
assignStringList
String assignStringList(List<?> objects)
Define a variable corresponding to a character array in the R context, given a List of Strings.- Parameters:
objects
- , which will be stringified if they are not strings.- Returns:
- the name of the variable in the R context.
-
booleanDoubleArrayEval
boolean booleanDoubleArrayEval(String command, String argName, double[] arg)
Run a command that takes a double array as an argument and returns a boolean.- Parameters:
command
-argName
-arg
-- Returns:
-
dataFrame
String dataFrame(ObjectMatrix<String,String,Object> matrix)
Convert an object matrix into an R data frame. Columns that look numeric are treated as numbers. Booleans and Strings are treated as factors.- Parameters:
matrix
-- Returns:
- variable name in R-land.
-
dataFrameEval
ObjectMatrix<String,String,Object> dataFrameEval(String command)
Evaluate a command that returns a dataFrame- Parameters:
command
-- Returns:
- an ObjectMatrix representation of the data frame.
-
doubleArrayDoubleArrayEval
double[] doubleArrayDoubleArrayEval(String command, String argName, double[] arg)
Run a command that has a single double array parameter, and returns a double array.- Parameters:
command
-argName
-arg
-- Returns:
-
doubleArrayEval
double[] doubleArrayEval(String command)
Run a command that returns a double array with no arguments.- Parameters:
command
-- Returns:
-
doubleArrayTwoDoubleArrayEval
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.- Parameters:
command
-argName
-arg
-argName2
-arg2
-- Returns:
-
doubleTwoDoubleArrayEval
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.- Parameters:
command
-argName
-arg
-argName2
-arg2
-- Returns:
-
eval
org.rosuda.REngine.REXP eval(String command)
Evaluate the given command- Parameters:
command
-- Returns:
-
getLastError
String getLastError()
-
intArrayEval
int[] intArrayEval(String command)
-
isConnected
boolean isConnected()
-
linearModel
LinearModelSummary linearModel(double[] data, Map<String,List<?>> factors)
Lower level access to linear model. Fairly simple. Factors are assigned in turn.- 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
LinearModelSummary linearModel(double[] data, ObjectMatrix<String,String,Object> design)
- Parameters:
data
-design
- 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
List<?> listEval(Class<?> listEntryType, String command)
- Parameters:
listEntryType
- a hint about what type of object you want the list to contain. If you set this to be null, the method will try to guess, but caution is advised.command
- R command- Returns:
-
loadLibrary
boolean loadLibrary(String libraryName)
-
oneWayAnova
OneWayAnovaResult oneWayAnova(double[] data, List<String> factor)
Lower-level access to a simple one-way ANOVA- Parameters:
data
-factor
-- Returns:
-
oneWayAnovaEval
Map<String,OneWayAnovaResult> oneWayAnovaEval(String command)
-
remove
void remove(String variableName)
Remove a variable from the R namespace- Parameters:
variableName
-
-
retrieveMatrix
DoubleMatrix<String,String> retrieveMatrix(String variableName)
Get a matrix back out of the R context. Row and Column names are filled in for the resulting object, if they are present.- Parameters:
variableName
-- Returns:
-
rowApplyLinearModel
Map<String,LinearModelSummary> rowApplyLinearModel(String dataMatrixVarName, String modelFormula, String[] factorNames)
Run lm with anova on all the rows of a matrix- 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.names
- of the factors like {"f1", "f2"}.- Returns:
- map of row identifiers to populated LinearModelSummaries.
-
stringEval
String stringEval(String command)
Evaluate any command and return a string- Parameters:
command
-- Returns:
- string
-
twoWayAnova
TwoWayAnovaResult twoWayAnova(double[] data, List<String> factor1, List<String> factor2, boolean includeInteraction)
Lower-level access to two-way ANOVA- Parameters:
data
-factor1
-factor2
-includeInteraction
-- Returns:
- result with interaction term information null if includeInteraction = false
-
twoWayAnovaEval
Map<String,TwoWayAnovaResult> twoWayAnovaEval(String command, boolean withInteractions)
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.- Parameters:
command
-- Returns:
-
voidEval
void voidEval(String command)
-
-