Class RSConnection

java.lang.Object
fr.ens.biologie.genomique.eoulsan.util.r.RSConnection

public class RSConnection extends Object
This class define an enhanced connection to RServe.
Since:
1.2
Author:
Laurent Jourdren, Marion Gaussen
  • Constructor Details

    • RSConnection

      public RSConnection()
      Default constructor. Connect to the localhost.
    • RSConnection

      public RSConnection(String serverName)
      Public constructor.
      Parameters:
      serverName - RServe server to use
  • Method Details

    • getRConnection

      public org.rosuda.REngine.Rserve.RConnection getRConnection() throws org.rosuda.REngine.REngineException
      Get the R connection.
      Returns:
      Returns the RConnection
      Throws:
      org.rosuda.REngine.REngineException - if an error occurs while connecting to the server
    • getServerName

      public String getServerName()
      Get the name of the Rserve server.
      Returns:
      the name of the Rserve server
    • writeStringAsFile

      public void writeStringAsFile(String outputFilename, String value) throws org.rosuda.REngine.REngineException
      Write a file to the RServer.
      Parameters:
      outputFilename - the filename
      value - The content of the file
      Throws:
      org.rosuda.REngine.REngineException - if an error occurs while writing the file
    • getFileInputStream

      public InputStream getFileInputStream(String filename) throws org.rosuda.REngine.REngineException
      Create an inputStream on a file on RServer.
      Parameters:
      filename - Name of the file on RServer to load
      Returns:
      an inputStream
      Throws:
      org.rosuda.REngine.REngineException - if an exception occurs while reading file
    • getFileOutputStream

      public OutputStream getFileOutputStream(String filename) throws org.rosuda.REngine.REngineException
      Create an outputStream on a file on RServer.
      Parameters:
      filename - Name of the file on RServer to write
      Returns:
      an outputStream
      Throws:
      org.rosuda.REngine.REngineException - if an exception occurs while reading file
    • putFile

      public void putFile(Path inputFile, String rServeFilename) throws org.rosuda.REngine.REngineException
      Put a file from the RServer.
      Parameters:
      inputFile - input file of the file to put
      rServeFilename - filename of the file to put
      Throws:
      org.rosuda.REngine.REngineException - if an error occurs while downloading the file
    • putFile

      public void putFile(InputStream is, String rServeFilename) throws org.rosuda.REngine.REngineException
      Put a file from the RServer.
      Parameters:
      is - input stream of the file to put
      rServeFilename - filename of the file to put
      Throws:
      org.rosuda.REngine.REngineException - if an error occurs while downloading the file
    • getFile

      public void getFile(String rServeFilename, Path outputFile) throws org.rosuda.REngine.REngineException
      Get a file from the RServer.
      Parameters:
      rServeFilename - filename of the file to retrieve
      outputFile - output file of the file to retrieve
      Throws:
      org.rosuda.REngine.REngineException - if an error occurs while downloading the file
    • getFilesIntoZip

      public void getFilesIntoZip(List<String> rServeFilenames, Path zipFile) throws org.rosuda.REngine.REngineException
      Get a list of files from the RServer.
      Parameters:
      rServeFilenames - list of filenames of the files to retrieve
      zipFile - zip output file for the files to retrieve
      Throws:
      org.rosuda.REngine.REngineException - if an error occurs while downloading the file
    • removeFile

      public void removeFile(String filename) throws org.rosuda.REngine.REngineException
      Remove a file on the RServer.
      Parameters:
      filename - File to remove
      Throws:
      org.rosuda.REngine.REngineException - if connection cannot be established
    • removeAllFiles

      public void removeAllFiles() throws org.rosuda.REngine.REngineException, org.rosuda.REngine.REXPMismatchException
      Remove all the files of the working directory.
      Throws:
      org.rosuda.REngine.REngineException - if an error occurs while removing the file
      org.rosuda.REngine.REXPMismatchException - if an error occurs while removing the file
    • setCommandArgs

      public void setCommandArgs(List<String> arguments) throws org.rosuda.REngine.REngineException
      Override the commandArg() R function.
      Parameters:
      arguments - the arguments
      Throws:
      org.rosuda.REngine.REngineException - if an error occurs while executing R code
    • executeRCode

      public void executeRCode(String source) throws org.rosuda.REngine.REngineException
      Execute a R code.
      Parameters:
      source - code to execute
      Throws:
      org.rosuda.REngine.REngineException - if an error while executing the code
    • executeR

      public void executeR(String code) throws org.rosuda.REngine.REngineException
      Execute a R code.
      Parameters:
      code - code to execute
      Throws:
      org.rosuda.REngine.REngineException - if an error while executing the code
    • executeRnwCode

      public void executeRnwCode(String source) throws org.rosuda.REngine.REngineException
      Execute a R Sweave code.
      Parameters:
      source - code to execute
      Throws:
      org.rosuda.REngine.REngineException - if an error while executing the code
    • executeRnwCode

      public void executeRnwCode(String source, String latexOutput) throws org.rosuda.REngine.REngineException
      Execute a R Sweave code.
      Parameters:
      source - code to execute
      latexOutput - output latex filename
      Throws:
      org.rosuda.REngine.REngineException - if an error while executing the code
    • loadImage

      public Image loadImage(String filename) throws org.rosuda.REngine.REngineException
      Load an image.
      Parameters:
      filename - filename of the image on the server
      Returns:
      an Image object
      Throws:
      org.rosuda.REngine.REngineException - if an error while loading the image
    • getFileAsArray

      public byte[] getFileAsArray(String filename) throws org.rosuda.REngine.REngineException
      Get a file as a byte array.
      Parameters:
      filename - filename of the file on the server
      Returns:
      a byte array
      Throws:
      org.rosuda.REngine.REngineException - if an error while loading the file
    • openFile

      public org.rosuda.REngine.Rserve.RFileInputStream openFile(String filename) throws org.rosuda.REngine.REngineException
      Open a file to read on Rserve server.
      Parameters:
      filename - the filename
      Returns:
      an input stream
      Throws:
      org.rosuda.REngine.REngineException - if an error occurs while creating the input stream
    • getAllFiles

      public void getAllFiles(Path outPath) throws org.rosuda.REngine.REngineException, org.rosuda.REngine.REXPMismatchException
      Get all the file on the Rserve server.
      Parameters:
      outPath - the output path
      Throws:
      org.rosuda.REngine.REngineException - if an error occurs while retrieving the files
      org.rosuda.REngine.REXPMismatchException - if an error occurs while retrieving the files
    • listFiles

      public List<String> listFiles() throws org.rosuda.REngine.REngineException, org.rosuda.REngine.REXPMismatchException
      List files on Rserve server.
      Returns:
      files a String list of files names
      Throws:
      org.rosuda.REngine.REngineException - if an error occurs with the server
      org.rosuda.REngine.REXPMismatchException - if an error occurs with the server
    • disConnect

      public void disConnect()
      Destroy the connection to the Rserve server.