|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectorg.fhcrc.cpl.toolbox.statistics.RInterface
public class RInterface
A class with generic methods for interfacing with R. Hides all kinds of exceptions, both from R and from file IO
| Nested Class Summary | |
|---|---|
static class |
RInterface.RErrorReaderThread
Manages the R error inputstream. |
static class |
RInterface.RReaderThread
Latches onto the R process' input stream and doesn't let go TODO: provide a way to get access to just whatever was read since last time you checked |
static class |
RInterface.RWriterThread
Handles a single write of a byte array to R |
| Field Summary | |
|---|---|
protected static int |
DEFAULT_MAX_R_WAIT_MILLIS
|
protected static int |
expressionNumber
|
protected static int |
R_SLEEP_INCREMENT_MILLIS
|
| Constructor Summary | |
|---|---|
RInterface()
|
|
| Method Summary | |
|---|---|
protected static java.lang.String |
collectInput(RInterface.RReaderThread readerThread,
java.lang.Process p,
java.lang.String endResponseSentinel,
int maxMillisToWaitForResponse)
Talks to the ReaderThread to check periodically for the specified sentinel. |
static java.lang.String |
evaluateRCommand(java.lang.String rCommand)
Evaluate an R command, giving it the default amount of time to respond |
static java.lang.String |
evaluateRCommand(java.lang.String rCommand,
int maxMillisToWaitForResponse)
Evaluate an R command, or series of commands. |
static java.lang.String |
evaluateRExpression(java.lang.String rExpression,
java.util.Map<java.lang.String,double[]> vectorVariableValues,
java.util.Map<java.lang.String,double[][]> matrixVariableValues,
java.lang.String[] dependentPackageNames)
Cover method with default wait time |
static java.lang.String |
evaluateRExpression(java.lang.String rExpression,
java.util.Map<java.lang.String,double[]> vectorVariableValues,
java.util.Map<java.lang.String,double[][]> matrixVariableValues,
java.lang.String[] dependentPackageNames,
int maxMillisToWaitForResponse)
|
static java.lang.String |
evaluateRExpression(java.lang.String rExpression,
java.util.Map<java.lang.String,double[]> variableValues,
java.lang.String[] dependentPackageNames)
cover method with default wait time, vector variables only |
static java.lang.String |
evaluateRExpression(java.lang.String rExpression,
java.util.Map<java.lang.String,double[]> variableValues,
java.lang.String[] dependentPackageNames,
int maxMillisToWaitForResponse)
Generic method for running an R expression and feeding the output to a file. |
static java.lang.String |
evaluateRExpression(java.lang.String rExpression,
java.util.Map<java.lang.String,java.lang.Object> scalarVariableValues,
java.util.Map<java.lang.String,double[]> vectorVariableValues,
java.util.Map<java.lang.String,double[][]> matrixVariableValues,
java.lang.String[] dependentPackageNames,
int maxMillisToWaitForResponse)
Generic method for running an R expression and feeding the output to a file. |
static java.util.Map<java.lang.String,java.lang.String> |
extractVariableStringsFromListOutput(java.lang.String listOutput)
Given R output, extract a map from variable names provided by a "list" command, to the strings that contain the values |
static java.lang.String |
generateRFriendlyPath(java.io.File file)
R doesn't like backslashes, even on Windows. |
static java.lang.String |
generateRFriendlyPath(java.lang.String filePath)
|
protected static java.lang.String |
getRCommandStringForOS()
Choose the right name of the command for running R for this OS |
static java.util.List<java.lang.Float> |
parseNumericList(java.lang.String varString)
Parse an R list result as a list of Floats |
protected static java.util.List<java.lang.Float> |
processCoefficientOnlyLine(java.lang.String coefficientLine)
Parse the important bits of a response from R's 'coeff' command |
static double[] |
processRCoefficientResponse(java.lang.String rResponse)
cute little method that handles a n R coefficients() response by ignoring the first line and splitting the second around whitespace. |
static float[][] |
processRMatrixResponse(java.lang.String rResponse)
First index in response indicates row. |
static java.lang.String |
readResourceFile(java.lang.String resourcePath)
Read in a fully-qualified resource on the classpath, i.e., an R script |
static boolean |
runRScript(java.io.File rScriptFile,
java.lang.Object caller)
Run an R script, setting the R directory to be the temp dir. |
protected static void |
tellRToQuit(java.io.DataOutputStream rOut)
|
static void |
writeToR(java.io.DataOutputStream rOut,
byte[] bytesToWrite)
Cover method to start up a writer thread, send it some bytes, and make sure they got written |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
protected static int expressionNumber
protected static final int DEFAULT_MAX_R_WAIT_MILLIS
protected static final int R_SLEEP_INCREMENT_MILLIS
| Constructor Detail |
|---|
public RInterface()
| Method Detail |
|---|
protected static java.lang.String getRCommandStringForOS()
public static boolean runRScript(java.io.File rScriptFile,
java.lang.Object caller)
throws java.lang.RuntimeException
rScriptFile -
java.lang.RuntimeExceptionpublic static float[][] processRMatrixResponse(java.lang.String rResponse)
rResponse -
public static double[] processRCoefficientResponse(java.lang.String rResponse)
throws java.lang.NumberFormatException
rResponse -
java.lang.NumberFormatExceptionprotected static java.util.List<java.lang.Float> processCoefficientOnlyLine(java.lang.String coefficientLine)
coefficientLine -
public static java.util.List<java.lang.Float> parseNumericList(java.lang.String varString)
varString -
public static java.util.Map<java.lang.String,java.lang.String> extractVariableStringsFromListOutput(java.lang.String listOutput)
listOutput -
public static java.lang.String evaluateRCommand(java.lang.String rCommand)
rCommand - command to execute
protected static java.lang.String collectInput(RInterface.RReaderThread readerThread,
java.lang.Process p,
java.lang.String endResponseSentinel,
int maxMillisToWaitForResponse)
throws java.io.IOException
readerThread - endResponseSentinel - maxMillisToWaitForResponse -
java.io.IOException
public static void writeToR(java.io.DataOutputStream rOut,
byte[] bytesToWrite)
throws java.io.IOException
rOut - bytesToWrite -
java.io.IOException
public static java.lang.String readResourceFile(java.lang.String resourcePath)
throws java.io.IOException
resourcePath -
java.io.IOException
public static java.lang.String evaluateRCommand(java.lang.String rCommand,
int maxMillisToWaitForResponse)
rCommand - maxMillisToWaitForResponse -
protected static void tellRToQuit(java.io.DataOutputStream rOut)
throws java.io.IOException
java.io.IOException
public static java.lang.String evaluateRExpression(java.lang.String rExpression,
java.util.Map<java.lang.String,double[]> variableValues,
java.lang.String[] dependentPackageNames)
rExpression - variableValues - dependentPackageNames -
public static java.lang.String evaluateRExpression(java.lang.String rExpression,
java.util.Map<java.lang.String,double[]> variableValues,
java.lang.String[] dependentPackageNames,
int maxMillisToWaitForResponse)
rExpression -
public static java.lang.String evaluateRExpression(java.lang.String rExpression,
java.util.Map<java.lang.String,double[]> vectorVariableValues,
java.util.Map<java.lang.String,double[][]> matrixVariableValues,
java.lang.String[] dependentPackageNames)
rExpression - vectorVariableValues - matrixVariableValues - dependentPackageNames -
public static java.lang.String evaluateRExpression(java.lang.String rExpression,
java.util.Map<java.lang.String,double[]> vectorVariableValues,
java.util.Map<java.lang.String,double[][]> matrixVariableValues,
java.lang.String[] dependentPackageNames,
int maxMillisToWaitForResponse)
public static java.lang.String generateRFriendlyPath(java.io.File file)
file -
public static java.lang.String generateRFriendlyPath(java.lang.String filePath)
public static java.lang.String evaluateRExpression(java.lang.String rExpression,
java.util.Map<java.lang.String,java.lang.Object> scalarVariableValues,
java.util.Map<java.lang.String,double[]> vectorVariableValues,
java.util.Map<java.lang.String,double[][]> matrixVariableValues,
java.lang.String[] dependentPackageNames,
int maxMillisToWaitForResponse)
rExpression -
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||