Package com.github.rcaller.rstuff
Class RCaller
- java.lang.Object
-
- com.github.rcaller.rstuff.RCaller
-
public class RCaller extends Object
- Author:
- Mehmet Hakan Satman mhsatman@yahoo.com http://stdioe.blogspot.com http://www.mhsatman.com http://code.google.com/p/rcaller
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedRCaller(RCode rCode, ROutputParser parser, RStreamHandler rOutput, RStreamHandler rError, MessageSaver messageSaver, TempFileService tempFileService, RCallerOptions rCallerOptions)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static RCallercreate()Static factory creator for the default objectstatic RCallercreate(RCallerOptions rCallerOptions)Static factory creator with startup optionsstatic RCallercreate(RCode rcode, RCallerOptions rCallerOptions)Static factory creator with given R code and startup optionsvoiddeleteTempFiles()RCaller uses temp directory for many cases.StringgetCranRepos()ROutputParsergetParser()RCallerOptionsgetRCallerOptions()RCodegetRCode()voidredirectROutputToFile(String name, boolean appendToExisting)voidredirectROutputToStream(OutputStream o)voidrunAndReturnResult(String var)Runs the current code and returns the R variable "var".voidrunAndReturnResultOnline(String var)Runs the current code in the existing R instance (or in a new one) and returns the R variable "var".voidrunAndReturnResultOnline(String var, boolean addTryCatch)Runs the current code in the existing R instance (or in a new one) and returns the R variable "var".voidrunOnly()Executes the code contained in this RCaller instance in s separate process.voidsetGraphicsTheme(GraphicsTheme theme)voidsetRCode(RCode rcode)voidstartStreamConsumers(Process process)voidstopRCallerAsync()Stops underlying R process anyway.voidStopRCallerAsync()Deprecated.voidstopRCallerOnline()Stops underlying R process gracefully.voidStopRCallerOnline()Deprecated.booleanstopStreamConsumers()Stops the threads that are emptying the output and error streams of the live but idle R process.
-
-
-
Constructor Detail
-
RCaller
protected RCaller(RCode rCode, ROutputParser parser, RStreamHandler rOutput, RStreamHandler rError, MessageSaver messageSaver, TempFileService tempFileService, RCallerOptions rCallerOptions)
-
-
Method Detail
-
create
public static RCaller create()
Static factory creator for the default object- Returns:
- default RCaller object
-
create
public static RCaller create(RCallerOptions rCallerOptions)
Static factory creator with startup options- Parameters:
rCallerOptions- given startup options- Returns:
- RCaller object
-
create
public static RCaller create(RCode rcode, RCallerOptions rCallerOptions)
Static factory creator with given R code and startup options- Parameters:
rcode- RCode object that contains R code that will be run at the startuprCallerOptions- given startup object- Returns:
- RCaller object
-
stopStreamConsumers
public boolean stopStreamConsumers()
Stops the threads that are emptying the output and error streams of the live but idle R process. If R is still working, this may cause it to hang. If R has finished execution, these threads prevent the operating system from shutting it down, so that the same process is used. Invoke this method when you have used R online and are finished with it.- Returns:
- true if rOutput and rError are alive, else return false
-
startStreamConsumers
public void startStreamConsumers(Process process)
-
getCranRepos
public String getCranRepos()
- Returns:
- The default Cran repository
-
getParser
public ROutputParser getParser()
-
getRCode
public RCode getRCode()
-
setRCode
public void setRCode(RCode rcode)
-
setGraphicsTheme
public void setGraphicsTheme(GraphicsTheme theme)
-
deleteTempFiles
public void deleteTempFiles()
RCaller uses temp directory for many cases. This sometimes causes inflations of number of temporary files. This method deletes the file created by RCaller in temp directory.
-
runOnly
public void runOnly() throws ExecutionExceptionExecutes the code contained in this RCaller instance in s separate process. Upon completion the process is killed and none of the R variables are returned- Throws:
ExecutionException- if R cannot be run for some reason
-
runAndReturnResultOnline
public void runAndReturnResultOnline(String var) throws ExecutionException
Runs the current code in the existing R instance (or in a new one) and returns the R variable "var". The R process is kept alive and can be re-used by invoking this method again. When you are done with this process, you must explicitly stop it. If R raises an error, it is ignored. For throwing them in Java, userunAndReturnResultOnline(String, boolean)with addTryCatch=true- Parameters:
var- The R variable to return- Throws:
ExecutionException- if R cannot be started- See Also:
stopStreamConsumers()
-
runAndReturnResultOnline
public void runAndReturnResultOnline(String var, boolean addTryCatch) throws ExecutionException
Runs the current code in the existing R instance (or in a new one) and returns the R variable "var". The R process is kept alive and can be re-used by invoking this method again. When you are done with this process, you must explicitly stop it.- Parameters:
var- The R variable to returnaddTryCatch- wrap original R code to tryCatch function (can impact performance)- Throws:
ExecutionException- if R cannot be started or raise error inside while addTryCatch parameter is true- Since:
- 4.0.0
- See Also:
stopStreamConsumers()
-
StopRCallerOnline
@Deprecated public void StopRCallerOnline()
Deprecated.Stops underlying R process gracefully. No calculations should be running.
-
stopRCallerOnline
public void stopRCallerOnline()
Stops underlying R process gracefully. No calculations should be running.
-
StopRCallerAsync
@Deprecated public void StopRCallerAsync()
Deprecated.Stops underlying R process anyway. May be used from separate thread to terminate running calculations.
-
stopRCallerAsync
public void stopRCallerAsync()
Stops underlying R process anyway. May be used from separate thread to terminate running calculations.
-
runAndReturnResult
public void runAndReturnResult(String var) throws ExecutionException
Runs the current code and returns the R variable "var". The R process is terminated upon completion of this method.- Parameters:
var- the R variable to return- Throws:
ExecutionException- if R could be started; if a temporary file to store the results could not be created; if the temporary file is corrupt. The exact cause will be added to the stack trace
-
redirectROutputToFile
public void redirectROutputToFile(String name, boolean appendToExisting) throws FileNotFoundException
- Throws:
FileNotFoundException
-
redirectROutputToStream
public void redirectROutputToStream(OutputStream o)
-
getRCallerOptions
public RCallerOptions getRCallerOptions()
-
-