org.nuiton.j2r
Class RProxy

java.lang.Object
  extended by org.nuiton.j2r.RProxy
All Implemented Interfaces:
REngine

public class RProxy
extends Object
implements REngine

This class allows to initialize a REngine without knowing which implementation is chosen. The implementation detection is based on the JVM's options :

It is possible to parametrize the network solution, for that, see the RNetEngine documentation.


Constructor Summary
RProxy()
          Constructor.
 
Method Summary
 void clearSession()
          Method to remove all objects from the R session.
 void commit()
          Method to launch the evaluation of all the R expressions stored when in non-autocommit mode.
 void cp(String inputObject, String outputObject)
          Method similar to the linux cp command : copy a R object.
 void dget(String rObject, File inputFile)
          Use the dget R instruction to store the content of a file (created with the dput instruction) into a R object.
 void dget(String rObject, String inputFileName)
          Use the dget R instruction to store the content of a file (created with the dput R instruction) into a R object.
 void dput(String rObject, File outputFile)
          Use the dput R instruction to store the content of a R object to a file.
 void dput(String rObject, String outputFileName)
          Use the dput R instruction to store the content of a R object to a file.
 Object eval(String expr)
          Send a R instruction to the engine and get the result back.
 File getwd()
          Get the actual R session working directory
 boolean init()
          Get back the R engine type options to initialize the REngine.
 Boolean isAutoCommit()
          Method to know the autocommit mode : true : autocommit mode false : non-autocommit mode
 void loadRData(File directory)
          Load .RData file located in directory
 void loadRData(File directory, String fileName)
          Load a specific R session : Load the "fileName.RData" file located in directory.
 void loadRData(String filename)
          Load filename.RData file located in current working directory
 String[] ls()
          Method to get all the R objects present in session.
 void mv(String source, String destination)
          Method similar to the linux mv command : rename a R object.
 void remove(String rObject)
          Remove an object from the R session using the remove(rObject) R function.
 void saveRData(File directory)
          Save the session in a .RData file in directory
 void saveRData(File directory, String fileName)
          Save a R session in a fileName.RData file located in directory.
 void saveRData(String filename)
          Save a R session in a filename.RData file located in the current working directory
 void setAutoCommit(Boolean autocommit)
          Method to set the autocommit mode : true : autocommit mode false : non-autocommit mode
 void setwd(File directory)
          Set the R working directory
 void terminate()
          Terminate the R engine.
 void voidEval(String expr)
          Send a R instruction to the engine without getting back its result.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RProxy

public RProxy()
       throws RException
Constructor. Launches the initialization.

Throws:
RException - if initialisation failed
Method Detail

eval

public Object eval(String expr)
            throws RException
Send a R instruction to the engine and get the result back.

Specified by:
eval in interface REngine
Parameters:
expr - the R instruction to send.
Returns:
the result of the R instruction.
Throws:
RException - if an error occur while trying to evaluate the expression.
See Also:
REngine.eval(java.lang.String)

init

public boolean init()
Get back the R engine type options to initialize the REngine.

Specified by:
init in interface REngine
Returns:
true/false to indicate if the initialization was succesful.
See Also:
REngine.init()

terminate

public void terminate()
               throws RException
Terminate the R engine.

Specified by:
terminate in interface REngine
Throws:
RException
See Also:
REngine.terminate()

voidEval

public void voidEval(String expr)
              throws RException
Send a R instruction to the engine without getting back its result.

Specified by:
voidEval in interface REngine
Parameters:
expr - the R instruction to send.
Throws:
RException - if an error occured while trying to evaluate the expression.
See Also:
REngine.voidEval(java.lang.String)

loadRData

public void loadRData(File directory)
               throws RException
Load .RData file located in directory

Specified by:
loadRData in interface REngine
Parameters:
directory - directory where the .RData file is located
Throws:
RException - if an error occcur while loading the R session.
See Also:
REngine.loadRData(java.io.File), REngineAbstract.loadRData(java.io.File)

saveRData

public void saveRData(File directory)
               throws RException
Save the session in a .RData file in directory

Specified by:
saveRData in interface REngine
Parameters:
directory - where the .RData file will be saved
Throws:
RException - if an error occur while saving the R session.
See Also:
REngine.saveRData(java.io.File), REngineAbstract.saveRData(java.io.File)

setwd

public void setwd(File directory)
           throws RException
Set the R working directory

Specified by:
setwd in interface REngine
Parameters:
directory - the new working directory to set.
Throws:
RException - if an error occur while setting the R working directory.
See Also:
REngine.setwd(java.io.File), REngineAbstract.setwd(java.io.File)

getwd

public File getwd()
           throws RException
Get the actual R session working directory

Specified by:
getwd in interface REngine
Returns:
a File that is the actual R session working directory, null if the engine is not initialized.
Throws:
RException - if an error occur while getting the R working directory.
See Also:
REngine.getwd(), REngineAbstract.getwd()

dput

public void dput(String rObject,
                 String outputFileName)
          throws RException
Use the dput R instruction to store the content of a R object to a file. The file created will be in the working directory

Specified by:
dput in interface REngine
Parameters:
rObject - name of the R object to save
outputFileName - name of the file to save
Throws:
RException - if an error occur while saving the content of the object.
See Also:
REngine.dput(java.lang.String, java.lang.String), REngineAbstract.dput(java.lang.String, java.lang.String)

dget

public void dget(String rObject,
                 String inputFileName)
          throws RException
Use the dget R instruction to store the content of a file (created with the dput R instruction) into a R object. The file used have to be in the working directory

Specified by:
dget in interface REngine
Parameters:
rObject - name of the R object created
inputFileName - name of the file to load
Throws:
RException - if an error occur while trying to perform this operation.
See Also:
REngine.dget(java.lang.String, java.lang.String), REngineAbstract.dget(java.lang.String, java.lang.String)

dput

public void dput(String rObject,
                 File outputFile)
          throws RException
Use the dput R instruction to store the content of a R object to a file.

Specified by:
dput in interface REngine
Parameters:
rObject - R object to save
outputFile - the file to save
Throws:
RException - if an error occur while performing the operation.
See Also:
REngine.dput(java.lang.String, java.io.File), REngineAbstract.dput(java.lang.String, java.io.File)

dget

public void dget(String rObject,
                 File inputFile)
          throws RException
Use the dget R instruction to store the content of a file (created with the dput instruction) into a R object.

Specified by:
dget in interface REngine
Parameters:
rObject - name of the R object created
inputFile - file to load
Throws:
RException - if an eroor occur while performing the operation.
See Also:
REngine.dget(java.lang.String, java.io.File), REngineAbstract.dget(java.lang.String, java.io.File)

remove

public void remove(String rObject)
            throws RException
Remove an object from the R session using the remove(rObject) R function.

Specified by:
remove in interface REngine
Parameters:
rObject - name of the R object to remove.
Throws:
RException - if an error occur while removing the R object.
See Also:
REngine.remove(java.lang.String), REngineAbstract.remove(java.lang.String)

mv

public void mv(String source,
               String destination)
        throws RException
Method similar to the linux mv command : rename a R object.

Specified by:
mv in interface REngine
Parameters:
source - the source R object name
destination - the destination R object name
Throws:
RException - if an error occur while renaming the R object.
See Also:
REngine.mv(java.lang.String, java.lang.String), REngineAbstract.mv(java.lang.String, java.lang.String)

cp

public void cp(String inputObject,
               String outputObject)
        throws RException
Method similar to the linux cp command : copy a R object.

Specified by:
cp in interface REngine
Parameters:
inputObject - the source R object naame
outputObject - the destination R object name
Throws:
RException - if an error occur while copying the R object.
See Also:
REngine.cp(java.lang.String, java.lang.String), REngineAbstract.cp(java.lang.String, java.lang.String)

ls

public String[] ls()
            throws RException
Method to get all the R objects present in session.

Specified by:
ls in interface REngine
Returns:
a table containing all the R objects present in session.
Throws:
RException - if an error occur while getting back the objects list.
See Also:
REngine.ls(), REngineAbstract.ls()

clearSession

public void clearSession()
                  throws RException
Method to remove all objects from the R session.

Specified by:
clearSession in interface REngine
Throws:
RException - if an error occur while clearing the R session.
See Also:
REngine.clearSession(), REngineAbstract.clearSession()

commit

public void commit()
            throws RException
Method to launch the evaluation of all the R expressions stored when in non-autocommit mode.

Specified by:
commit in interface REngine
Throws:
RException - if an error occur while evaluating one of the R expressions.
See Also:
REngine.commit(), REngine.commit()

setAutoCommit

public void setAutoCommit(Boolean autocommit)
                   throws RException
Method to set the autocommit mode :

Specified by:
setAutoCommit in interface REngine
Parameters:
autocommit - the autocommit mode
Throws:
RException - if an error occur while switching modes.
See Also:
REngine.setAutoCommit(java.lang.Boolean), REngine.setAutoCommit(java.lang.Boolean)

isAutoCommit

public Boolean isAutoCommit()
Method to know the autocommit mode :

Specified by:
isAutoCommit in interface REngine
Returns:
the autocommit mode
See Also:
REngine.isAutoCommit(), REngineAbstract.isAutoCommit()

saveRData

public void saveRData(File directory,
                      String fileName)
               throws RException
Save a R session in a fileName.RData file located in directory.

Specified by:
saveRData in interface REngine
Parameters:
directory - where the ".RData" file will be located
fileName - name of the file to save (will save in the fileName.RData file)
Throws:
RException - if an error occur while saving the R session.
See Also:
REngine.saveRData(java.io.File, java.lang.String), REngineAbstract.saveRData(java.io.File, java.lang.String)

loadRData

public void loadRData(File directory,
                      String fileName)
               throws RException
Load a specific R session : Load the "fileName.RData" file located in directory.

Specified by:
loadRData in interface REngine
Parameters:
directory - directory where the ".RData" file is located
fileName - name of the file to load (will load the fileName.RData file)
Throws:
RException - if an error occur while loading the R session file.
See Also:
REngine.loadRData(java.io.File, java.lang.String), REngineAbstract.loadRData(java.io.File, java.lang.String)

saveRData

public void saveRData(String filename)
               throws RException
Description copied from interface: REngine
Save a R session in a filename.RData file located in the current working directory

Specified by:
saveRData in interface REngine
Throws:
RException

loadRData

public void loadRData(String filename)
               throws RException
Description copied from interface: REngine
Load filename.RData file located in current working directory

Specified by:
loadRData in interface REngine
Parameters:
filename - name of the .RData file (will be followed by .RData)
Throws:
RException


Copyright © 2006-2010 CodeLutin. All Rights Reserved.