org.nuiton.j2r.types
Class RDataFrame

java.lang.Object
  extended by org.nuiton.j2r.types.REXPAbstract
      extended by org.nuiton.j2r.types.RDataFrame
All Implemented Interfaces:
REXP

public class RDataFrame
extends REXPAbstract
implements REXP

Java implementation of the R data.frame

Author:
couteau

Field Summary
 
Fields inherited from class org.nuiton.j2r.types.REXPAbstract
attributes, dataInconsistencyText, engine, indexExceptionText, names, noVariable, variable
 
Constructor Summary
RDataFrame(REngine engine)
          Constructor
RDataFrame(REngine engine, List<String> names, List<String> rowNames, List<List<?>> data, String variable)
          Constructor
RDataFrame(REngine engine, Object[] datatypes, int y)
          Constructor
RDataFrame(REngine engine, String[] names, String[] rowNames, List<List<? extends Object>> data, String variable)
          Constructor, used for autoconversion from rexp to data.frame.
 
Method Summary
 void checkX(int x)
          Check if the index is into the data.frame length throws a IndexOutOfBoundsException if not the index is too big.
 int[] dim()
           
 void exportCsv(File outputFile, boolean rowNames, boolean names)
          Export the data.frame into csv format.
 Object get(int x, int y)
          Method to get the object located at the [x,y] coordinates.
 List<List<? extends Object>> getData()
          Method to get the ArrayLists of the R data.frame (there is no synchronizing with R).
 void getFrom(String variable)
          Method to get a data.frame from a variable in R.
 String getRowName(int y)
          Method to get the row name of the row index y+1 of the R data.frame.
 List<String> getRowNames()
          Method to get the names of the rows of the R data.frame
 void importCsv(File inputFile, boolean rowNames, boolean names)
          Import a dataframe form a csv file.
 void importCsv(File inputFile, boolean rowNames, boolean names, List<Object> importTypes)
          Import a dataframe from a csv file.
 void importCsv(File inputFile, boolean rowNames, boolean names, Object importType)
          Import a dataframe form a csv file.
 void set(int x, int y, Object data)
          Method to set the value (x,y) to a Double value.
 void setData(List<List<? extends Object>> data)
          Method to assign the data of the R data.frame (there is no synchronizing with R, use the commit() method to send data to R.
 void setRowName(int x, String rowName)
          Method to assign the name of the ArrayList at the index x.
 void setRowNames(List<String> rowNames)
          Method to assign the names of the rows of the R data.frame
 String toRString()
          Method to export the data.frame in a String for evaluation in R.
 
Methods inherited from class org.nuiton.j2r.types.REXPAbstract
checkVariable, getAttribute, getAttributes, getEngine, getName, getNames, getVariable, setAttribute, setAttributes, setEngine, setName, setNames, setVariable
 
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.types.REXP
getAttribute, getAttributes, getVariable, setAttribute, setAttributes
 

Constructor Detail

RDataFrame

public RDataFrame(REngine engine)
Constructor

Parameters:
engine - the engine in which the data frame will be located.

RDataFrame

public RDataFrame(REngine engine,
                  Object[] datatypes,
                  int y)
           throws RException
Constructor

Parameters:
engine - the engine in which the data frame will be located.
datatypes - a table object determining the type of each column of the data.frame.
y - the length of each vector that compound the data.frame.
Throws:
RException

RDataFrame

public RDataFrame(REngine engine,
                  List<String> names,
                  List<String> rowNames,
                  List<List<?>> data,
                  String variable)
           throws RException
Constructor

Parameters:
engine - the engine in which the data frame will be located.
names - names of the the data.frame columns.
rowNames - names of the data.frame rows.
data - the data of the data.frame
variable - the name of the data.frame in R.
Throws:
RException - if an error occur while trying to initialize

RDataFrame

public RDataFrame(REngine engine,
                  String[] names,
                  String[] rowNames,
                  List<List<? extends Object>> data,
                  String variable)
Constructor, used for autoconversion from rexp to data.frame.

Parameters:
engine - the engine in which the data frame will be located.
names - names of the the data.frame columns.
rowNames - names of the data.frame rows.
data - the data of the data.frame
variable - the name of the data.frame in R.
Method Detail

getRowNames

public List<String> getRowNames()
                         throws RException
Method to get the names of the rows of the R data.frame

Returns:
a ArrayList of strings containing the names of each row of the R data.frame
Throws:
RException - if an error occurs while getting back the names from R.
IndexOutOfBoundsException - when the row.names size get from R is bigger than the local data size.

getRowName

public String getRowName(int y)
                  throws RException
Method to get the row name of the row index y+1 of the R data.frame.

Parameters:
y - index of the row (0 to n-1)
Returns:
the name of the ArrayList
Throws:
RException - if an error occurs while getting back the row name from R.

setRowNames

public void setRowNames(List<String> rowNames)
                 throws RException
Method to assign the names of the rows of the R data.frame

Parameters:
rowNames - a ArrayList containing the names of the rows of the R data.frame
Throws:
RException - if an error occur while in R.
IndexOutOfBoundsException - when the row names ArrayList is longer than the data.frame length

setRowName

public void setRowName(int x,
                       String rowName)
                throws RException
Method to assign the name of the ArrayList at the index x.

Parameters:
x - index of the ArrayList (0 to n-1)
rowName - Name of the ArrayList.
Throws:
RException - if an error occur while in R.
IndexOutOfBoundsException - when the index is out of the data.frame bounds.

toRString

public String toRString()
                 throws RException
Method to export the data.frame in a String for evaluation in R.

Specified by:
toRString in interface REXP
Returns:
a R string representation of the data.frame to create it in R.
Throws:
RException - If no variable name is given

set

public void set(int x,
                int y,
                Object data)
         throws RException
Method to set the value (x,y) to a Double value.

Parameters:
x - x coordinate (from 0 to size-1)
y - y coordinate (from 0 to size-1)
data - value to set
Throws:
RException - if no variable name has been given to the data.frame or the data type is not allowed at this location.

get

public Object get(int x,
                  int y)
           throws RException
Method to get the object located at the [x,y] coordinates.

Parameters:
x - x coordinates (between 0 and size-1)
y - y coordinates (between 0 and size-1)
Returns:
the Object located at the [x,y] coordinates
Throws:
RException - if no variable name has been given to the data.frame
IndexOutOfBoundsException - if the x or y coordinates are not correct.

getData

public List<List<? extends Object>> getData()
Method to get the ArrayLists of the R data.frame (there is no synchronizing with R).

Returns:
a ArrayList containing the ArrayLists of the R data.frame

setData

public void setData(List<List<? extends Object>> data)
             throws RException
Method to assign the data of the R data.frame (there is no synchronizing with R, use the commit() method to send data to R.

Parameters:
data - a ArrayList of ArrayLists, containing each ArrayList of the R data.frame
Throws:
RException

getFrom

public void getFrom(String variable)
             throws RException
Method to get a data.frame from a variable in R.

Specified by:
getFrom in interface REXP
Parameters:
variable - name of the data.frame in R
Throws:
RException

exportCsv

public void exportCsv(File outputFile,
                      boolean rowNames,
                      boolean names)
               throws IOException
Export the data.frame into csv format.

Parameters:
outputFile - the file to write
rowNames - true/false to determine if the row names will be put on the export.
names - true/false to determine if the column names will be put on the export.
Throws:
IOException

importCsv

public void importCsv(File inputFile,
                      boolean rowNames,
                      boolean names)
               throws FileNotFoundException,
                      IOException
Import a dataframe form a csv file. The dataframe will contain Strings. Use this method if you don't know the type of data that is in the csv file.

Parameters:
inputFile - Csv file to import.
rowNames - Does the csv file contains names of the rows.
names - Does the csv file contain names of the columns.
Throws:
FileNotFoundException
IOException

importCsv

public void importCsv(File inputFile,
                      boolean rowNames,
                      boolean names,
                      Object importType)
               throws FileNotFoundException,
                      IOException
Import a dataframe form a csv file. The dataframe will contain Objects of the same class than importType. Use this method if you know the type of data that is in the csv file.

Parameters:
inputFile - Csv file to import.
rowNames - Does the csv file contains names of the rows.
names - Does the csv file contain names of the columns.
importType - Object of the class of the data imported (all the data have the same type). (Supported types : String, Double and Integer)
Throws:
FileNotFoundException
IOException

importCsv

public void importCsv(File inputFile,
                      boolean rowNames,
                      boolean names,
                      List<Object> importTypes)
               throws FileNotFoundException,
                      IOException
Import a dataframe from a csv file. The dataframe will contain Objects of the same class than each element of importTypes (one element = one column). Use this method if you know the type of data that is in the csv file.

Parameters:
inputFile - Csv file to import.
rowNames - Does the csv file contains names of the rows.
names - Does the csv file contain names of the columns.
importTypes - ArrayList of Object of the class of the data imported (the ArrayList match the data type of the columns). (Supported types : String, Double and Integer)
Throws:
FileNotFoundException
IOException

checkX

public void checkX(int x)
Check if the index is into the data.frame length throws a IndexOutOfBoundsException if not the index is too big.

Specified by:
checkX in interface REXP
Parameters:
x - index

dim

public int[] dim()
          throws RException
Throws:
RException


Copyright © 2006-2010 CodeLutin. All Rights Reserved.