Class: DataFrame
Overview
Synopsis
This is an extended ERObj class inspired by the example given in the RPy manual used for R data frames. As with ERObj, methods caught by method_missing are converted into attribute calls on the R dataframe it represents. The rows and columns methods give access to the column and row names.
Usage
See examples/dataframe.rb for examples of usage.
–
Author
Alex Gutteridge
Copyright
Copyright © 2006 Alex Gutteridge
The Original Code is the RPy python module.
The Initial Developer of the Original Code is Walter Moreira. Portions created by the Initial Developer are Copyright © 2002 the Initial Developer. All Rights Reserved.
Contributor(s):
Gregory R. Warnes <[email protected]> (RPy Maintainer)
This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++
Instance Method Summary collapse
- #[](col) ⇒ Object
-
#columns ⇒ Object
Returns an array of the column names used in the R data frame.
- #method_missing(attr) ⇒ Object
-
#rows ⇒ Object
Returns an array of the row names used in the R data frame.
Methods inherited from ERObj
#as_r, #initialize, #lcall, #to_ruby, #to_s
Constructor Details
This class inherits a constructor from ERObj
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(attr) ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/rsruby/dataframe.rb', line 66 def method_missing(attr) attr = attr.to_s mode = RSRuby.get_default_mode RSRuby.set_default_mode(RSRuby::BASIC_CONVERSION) column_names = @r.colnames(@robj) if attr == column_names or column_names.include?(attr) RSRuby.set_default_mode(mode) return @r['$'].call(@robj,attr.to_s) end #? Not sure what here... RSRuby.set_default_mode(mode) return super(attr) end |
Instance Method Details
#[](col) ⇒ Object
62 63 64 |
# File 'lib/rsruby/dataframe.rb', line 62 def[](col) return @r['$'].call(@robj,col.to_s) end |
#columns ⇒ Object
Returns an array of the column names used in the R data frame.
56 57 58 59 60 |
# File 'lib/rsruby/dataframe.rb', line 56 def columns cols = @r.colnames(@robj) cols = [cols] unless cols.class == 'Array' return cols end |
#rows ⇒ Object
Returns an array of the row names used in the R data frame.
51 52 53 |
# File 'lib/rsruby/dataframe.rb', line 51 def rows return @r.attr(@robj, 'row.names') end |