Skip to content

Ruby library that integrates the R interpreter in Ruby, making R's statistical routines and graphics available within Ruby.

License

Notifications You must be signed in to change notification settings

sebastianzillessen/rinruby

 
 

Repository files navigation

Build Status Code Climate Test Coverage Issue Count

rinruby

Execute R code from Ruby.

INSTALL

  • gem install rootapp-rinruby

USAGE

require "rinruby"

R = RinRuby.new

n = 10
beta_0 = 1
beta_1 = 0.25
alpha = 0.05
seed = 23423
R.assign('x', (1..n).entries)
R.eval <<EOF
  set.seed(#{seed})
  y <- #{beta_0} + #{beta_1}*x + rnorm(#{n})
  fit <- lm( y ~ x )
  est <- round(coef(fit),3)
  pvalue <- summary(fit)$coefficients[2,4]
EOF
puts "E(y|x) ~= #{R.pull('est')[0]} + #{R.pull('est')[1]} * x"
if R.pull('pvalue') < alpha
  puts "Reject the null hypothesis and conclude that x and y are related."
else
  puts "There is insufficient evidence to conclude that x and y are related."
end

Please note:

The interface of RinRuby has slightly changed compared to the previous versions. Variables cannot be assigned directly anymore. But you need to use assign(name, value) to assign variables from the ruby side and pull(name) to retrieve assigned variables in R in Ruby.

REQUIREMENTS

  • R
  • Ruby >= 2.0.0

LICENSE

GPL-3. See LICENSE.txt for more information.

About

Ruby library that integrates the R interpreter in Ruby, making R's statistical routines and graphics available within Ruby.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Ruby 100.0%