org.nuiton.j2r
Class REngineAbstract

java.lang.Object
  extended by org.nuiton.j2r.REngineAbstract
All Implemented Interfaces:
REngine
Direct Known Subclasses:
RJniEngine, RNetEngine

public abstract class REngineAbstract
extends java.lang.Object
implements REngine

Abstract REngine that provides utility R methods (such as clear session, set working directory, import data, ...) for all R engines.

Author:
couteau

Constructor Summary
REngineAbstract()
           
 
Method Summary
 void clearSession()
          Method to clear the R session.
 void cp(java.lang.String source, java.lang.String destination)
          Copy a R Object into another one (similar to the linux cp instruction).
 void dget(java.lang.String rObject, java.io.File inputFile)
          Use the dget rInstruction to store the content of a file (created with the dput instruction) into a R object.
 void dget(java.lang.String rObject, java.lang.String inputFileName)
          Use the dget rInstruction to store the content of a file (created with the dput instruction) into a R object.
 void dput(java.lang.String rObject, java.io.File outputFile)
          Use the dput R instruction to store the content of a R object to a file.
 void dput(java.lang.String rObject, java.lang.String outputFileName)
          Use the dput R instruction to store the content of a R object to a file.
 java.io.File getwd()
          Get the actual R session working directory
 java.lang.Boolean isAutoCommit()
          Method to know if engine is in autocommit mode.
 void loadRData(java.io.File directory)
          Load a specific R session : Load .RData file located in directory
 void loadRData(java.io.File directory, java.lang.String fileName)
          Load a specific R session : Load the "fileName.RData" file located in directory.
 java.lang.String[] ls()
          Method to get all the R object in session.
 void mv(java.lang.String source, java.lang.String destination)
          Method similar to the linux mv instruction : move an object to a destination, or in this case, rename a R object.
 void remove(java.lang.String rObject)
          Remove a R object from the R session using the R method : remove(rObject).
 void saveRData(java.io.File directory)
          Save the session in a .RData file in directory
 void saveRData(java.io.File directory, java.lang.String fileName)
          Save a R session in a fileName.RData file located in directory.
 void setAutoCommit(java.lang.Boolean autocommit)
          Change the autocommit mode of the engine.
 void setwd(java.io.File directory)
          Set the R working directory
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.nuiton.j2r.REngine
commit, eval, init, terminate, voidEval
 

Constructor Detail

REngineAbstract

public REngineAbstract()
Method Detail

loadRData

public void loadRData(java.io.File directory)
               throws RException
Load a specific R session : 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 occur while loading the R session file

loadRData

public void loadRData(java.io.File directory,
                      java.lang.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.

saveRData

public void saveRData(java.io.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.

saveRData

public void saveRData(java.io.File directory,
                      java.lang.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.

setwd

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

Specified by:
setwd in interface REngine
Parameters:
directory - to set
Throws:
RException

getwd

public java.io.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
Throws:
RException

dput

public void dput(java.lang.String rObject,
                 java.lang.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

dget

public void dget(java.lang.String rObject,
                 java.lang.String inputFileName)
          throws RException
Use the dget rInstruction to store the content of a file (created with the dput 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

dput

public void dput(java.lang.String rObject,
                 java.io.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

dget

public void dget(java.lang.String rObject,
                 java.io.File inputFile)
          throws RException
Use the dget rInstruction 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

remove

public void remove(java.lang.String rObject)
            throws RException
Remove a R object from the R session using the R method : remove(rObject).

Specified by:
remove in interface REngine
Parameters:
rObject - name of the R object to be removed.
Throws:
RException - if an error occur while trying to remove the R object.

mv

public void mv(java.lang.String source,
               java.lang.String destination)
        throws RException
Method similar to the linux mv instruction : move an object to a destination, or in this case, rename a R object. Does : destination<-source remove(source)

Specified by:
mv in interface REngine
Parameters:
source - source R object name
destination - destination R object name
Throws:
RException - if an error occur while trying to move the R object.

cp

public void cp(java.lang.String source,
               java.lang.String destination)
        throws RException
Copy a R Object into another one (similar to the linux cp instruction). Does : destination<-source

Specified by:
cp in interface REngine
Parameters:
source - source R object name
destination - destination R object name
Throws:
RException - if an error occur while trying to assign the source to the destination

ls

public java.lang.String[] ls()
                      throws RException
Method to get all the R object in session. Return the result of the R ls() function.

Specified by:
ls in interface REngine
Returns:
the names of the R objects present in session as a String[]. The order of the names is given by their order given by the R ls() method, e.g. alphabetic order.
Throws:
RException - if an error occur while trying to list the R objects in session.

clearSession

public void clearSession()
                  throws RException
Method to clear the R session. Does : rm(list=ls())

Specified by:
clearSession in interface REngine
Throws:
RException - if an error occur while trying to clear the session

setAutoCommit

public void setAutoCommit(java.lang.Boolean autocommit)
                   throws RException
Change the autocommit mode of the engine. If switching from no-autocommit to autocommit mode, does a commit of all R instructions stored.

Specified by:
setAutoCommit in interface REngine
Parameters:
autocommit - true for autocommit mode, false for no-autocommit mode.
Throws:
RException - if an error occur while commiting all the R instructions stored.

isAutoCommit

public java.lang.Boolean isAutoCommit()
Method to know if engine is in autocommit mode.

Specified by:
isAutoCommit in interface REngine
Returns:
true if in autocommit mode, false otherwise.


Copyright © 2006-2009 CodeLutin. All Rights Reserved.