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
Modifier and TypeMethodDescriptionvoid
void
void
void
assignFactor
(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<?> 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.dataFrame
(ObjectMatrix<String, String, Object> matrix) Convert an object matrix into an R data frame.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
Evaluate the given commandint[]
intArrayEval
(String command) boolean
linearModel
(double[] data, Map<String, List<?>> factors) Lower level access to linear model.linearModel
(double[] data, ObjectMatrix<String, String, Object> design) List
<?> boolean
loadLibrary
(String libraryName) oneWayAnova
(double[] data, List<String> factor) Lower-level access to a simple one-way ANOVAoneWayAnovaEval
(String command) void
Remove a variable from the R namespaceretrieveMatrix
(String variableName) Get a matrix back out of the R context.rowApplyLinearModel
(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 formvoid
-
Method Details
-
assign
- Parameters:
argName
-arg
-
-
assign
-
assign
-
assign
-
assignFactor
- Parameters:
strings
-- Returns:
- the name of the factor generated.
-
assignFactor
- Parameters:
factorName
-list
-- Returns:
- the factor name
-
assignMatrix
Assign a 2-d matrix.- Parameters:
matrix
-- Returns:
- the name of the variable by which the R matrix can be referred.
-
assignMatrix
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
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
Run a command that takes a double array as an argument and returns a boolean.- Parameters:
command
-argName
-arg
-- Returns:
-
dataFrame
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
Evaluate a command that returns a dataFrame- Parameters:
command
-- Returns:
- an ObjectMatrix representation of the data frame.
-
doubleArrayDoubleArrayEval
Run a command that has a single double array parameter, and returns a double array.- Parameters:
command
-argName
-arg
-- Returns:
-
doubleArrayEval
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
Evaluate the given command- Parameters:
command
-- Returns:
-
getLastError
String getLastError() -
intArrayEval
-
isConnected
boolean isConnected() -
linearModel
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
- 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
- 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
-
oneWayAnova
Lower-level access to a simple one-way ANOVA- Parameters:
data
-factor
-- Returns:
-
oneWayAnovaEval
-
remove
Remove a variable from the R namespace- Parameters:
variableName
-
-
retrieveMatrix
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
Evaluate any command and return a string- Parameters:
command
-- Returns:
- string
-
stringListEval
-
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
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
-