Class: RSession

Inherits:
Object show all
Extended by:
Assertions::ClassMethods, Test::Unit::Assertions
Includes:
Assertions, Constants, Test::Unit::Assertions
Defined in:
app/models/r.rb

Defined Under Namespace

Modules: Assertions, Constants

Constant Summary

Constants included from Constants

Constants::Default_Session

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Assertions::ClassMethods

assert_invariant

Methods included from Assertions

#assert_invariant

Constructor Details

#initializeRSession


4
5
6
7
8
# File 'app/models/r.rb', line 4

def initialize
	@con=Rserve::Connection.new
	@log=[]
	eval("library(ggplot2)")
end

Class Method Details

.eval_R_shell(rCommand) ⇒ Object

assign


25
26
27
28
29
30
31
# File 'app/models/r.rb', line 25

def self.eval_R_shell(rCommand)
	shellCmd="R --save --quiet -e \'#{rCommand}\'"
	puts "shellCmd=#{shellCmd}" if $VERBOSE
	sysout=`#{shellCmd}`
	puts "sysout=#{sysout}" if $VERBOSE
	return sysout
end

Instance Method Details

#assign(variable, r_code) ⇒ Object


22
23
24
# File 'app/models/r.rb', line 22

def assign(variable, r_code)
	@con.assign(variable, r_code)
end

#eval(r_code) ⇒ Object

initialize


9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'app/models/r.rb', line 9

def eval(r_code)
	@log << r_code # Array of all expressions evaluated
	@con.eval(r_code)
rescue Rserve::Connection::EvalError => exception
	matchData=/status=error:'(.*)'/.match(exception.message)
	error_message=matchData[1]
	message=build_message(nil, "\n? error while evaluating R expression ?\n#{@log.join("\n")}", error_message, r_code)
	raise exception.exception(message) #quit on first error
rescue StandardError => exception
	message=build_message(nil, "\n? error while evaluating R expression ?\n", exception.message, r_code)
	raise exception.exception(message) #don't know anything about
ensure
end