Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Having a problem with using data frame in ruby #11

Open
kishorerathi opened this issue Dec 7, 2011 · 0 comments
Open

Having a problem with using data frame in ruby #11

kishorerathi opened this issue Dec 7, 2011 · 0 comments

Comments

@kishorerathi
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant