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 Summary
Constructors Constructor Description RSConnection()
Default constructor.RSConnection(String serverName)
Public constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
disConnect()
Destroy the connection to the Rserve server.void
executeRCode(String source)
Execute a R code.void
executeRnwCode(String source)
Execute a R Sweave code.void
executeRnwCode(String source, String latexOutput)
Execute a R Sweave code.void
getAllFiles(File outPath)
Get all the file on the Rserve server.void
getFile(String rServeFilename, File outputFile)
Get a file from the RServer.byte[]
getFileAsArray(String filename)
Get a file as a byte array.InputStream
getFileInputStream(String filename)
Create an inputStream on a file on RServer.OutputStream
getFileOutputStream(String filename)
Create an outputStream on a file on RServer.void
getFilesIntoZip(List<String> rServeFilenames, File zipFile)
Get a list of files from the RServer.org.rosuda.REngine.Rserve.RConnection
getRConnection()
Get the R connection.String
getServerName()
Get the name of the Rserve server.List<String>
listFiles()
List files on Rserve server.Image
loadImage(String filename)
Load an image.org.rosuda.REngine.Rserve.RFileInputStream
openFile(String filename)
Open a file to read on Rserve server.void
putFile(File inputFile, String rServeFilename)
Put a file from the RServer.void
putFile(InputStream is, String rServeFilename)
Put a file from the RServer.void
removeAllFiles()
Remove all the files of the working directory.void
removeFile(String filename)
Remove a file on the RServer.void
setCommandArgs(List<String> arguments)
Override the commandArg() R function.void
writeStringAsFile(String outputFilename, String value)
Write a file to the RServer.
-
-
-
Constructor Detail
-
RSConnection
public RSConnection()
Default constructor. Connect to the localhost.
-
RSConnection
public RSConnection(String serverName)
Public constructor.- Parameters:
serverName
- RServe server to use
-
-
Method Detail
-
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 filenamevalue
- 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(File inputFile, String rServeFilename) throws org.rosuda.REngine.REngineException
Put a file from the RServer.- Parameters:
inputFile
- input file of the file to putrServeFilename
- 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 putrServeFilename
- 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, File outputFile) throws org.rosuda.REngine.REngineException
Get a file from the RServer.- Parameters:
rServeFilename
- filename of the file to retrieveoutputFile
- 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, File zipFile) throws org.rosuda.REngine.REngineException
Get a list of files from the RServer.- Parameters:
rServeFilenames
- list of filenames of the files to retrievezipFile
- 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
-
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 fileorg.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
-
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 executelatexOutput
- 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(File 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 filesorg.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 serverorg.rosuda.REngine.REXPMismatchException
- if an error occurs with the server
-
disConnect
public void disConnect()
Destroy the connection to the Rserve server.
-
-