alexgutteridge / rsruby

Ruby - R bridge.
http://rubyforge.org/projects/rsruby/
GNU Lesser General Public License v2.1
332 stars 59 forks source link

Having a problem with using data frame in ruby #11

Open kishorerathi opened 12 years ago

kishorerathi commented 12 years ago

Dear Alex

Sincere Greetings.

I am trying to use RSRuby to drive a massive number of linear model executions in R via Ruby using RSRuby. I have stuck a wall here and need your help to get through. Here is the code which is coughing error

require 'rubygems' require 'pp' require 'rsruby' require 'rsruby/dataframe'

r = RSRuby.instance r.class_table['data.frame'] = lambda {|x| DataFrame.new(x)} RSRuby.set_default_mode(RSRuby::CLASS_CONVERSION)

get the data arrays setup appropriately all the arrays are of equal size here

x1 = [12, 34, 23, 35, 17, 19, 23, 29] x2 = [71, 85, 93, 66, 71, 81, 69, 55] x3 = [3, 5, 7, 2, 8, 7, 5, 8] y = [112, 134, 138, 145, 111, 149, 167, 156]

i_dfrm = {} i_dfrm['dy'] = y i_dfrm['x1'] = x1 i_dfrm['x2'] = x2 i_dfrm['x3'] = x3

Create the data frame dfrm

dfrm = r.as_data_frame(:x => i_dfrm)

pp r.names(dfrm)

Till here everything looks cool and works great

The following statement bombs out
trying the lm call using dfrm as a dataframe

r.eval_R("lm.res = lm(dy ~ x1 + x2 + x3, data=dfrm)")

Error Message is

=begin RException: Error in is.data.frame(data) : object 'dfrm' not found

from /usr/lib/ruby/gems/1.8/gems/rsruby-0.5.1.1/lib/rsruby.rb:148:in lcall' from /usr/lib/ruby/gems/1.8/gems/rsruby-0.5.1.1/lib/rsruby.rb:148:inmethod_missing' from /usr/lib/ruby/gems/1.8/gems/rsruby-0.5.1.1/lib/rsruby.rb:264:in `eval_R' from (irb):27 from /usr/local/lib/site_ruby/1.8/rubygems.rb:123 =end

Please help as my submission and passing/failing depends on it!!!!!!

Regards

Kishore