lib/rbbt/util/R.rb in rbbt-util-5.5.1 vs lib/rbbt/util/R.rb in rbbt-util-5.5.2
- old
+ new
@@ -20,11 +20,11 @@
cmd << File.open(command, 'r') do |f| f.read end
else
cmd << command
end
- Log.debug "R Script:\n#{ cmd }"
+ Log.debug{"R Script:\n#{ cmd }"}
if options.delete :monitor
io = CMD.cmd('R --vanilla --slave --quiet', options.merge(:in => cmd, :pipe => true))
while line = io.gets
puts line
@@ -33,23 +33,20 @@
else
CMD.cmd('R --vanilla --slave --quiet', options.merge(:in => cmd))
end
end
- def self.interactive(init_file, options = {})
- CMD.cmd("env R_PROFILE='#{init_file}' xterm R")
- end
-
def self.interactive(script, options = {})
TmpFile.with_file do |init_file|
Open.write(init_file) do |file|
file.puts "# Loading basic rbbt environment"
+ file.puts "library(utils);\n"
file.puts "source('#{R::UTIL}');\n"
file.puts
file.puts script
end
- CMD.cmd("env R_PROFILE='#{init_file}' xterm R")
+ CMD.cmd("env R_PROFILE='#{init_file}' xterm \"$RHOME/bin/R\"")
end
end
def self.ruby2R(object)
case object
@@ -96,12 +93,16 @@
TSV.open(f, open_options) unless open_options[:ignore_output]
end
end
end
- def R_interactive(open_options = {})
+ def R_interactive(pre_script = nil)
TmpFile.with_file do |f|
- Open.write(f, self.to_s)
- R.interactive("data_file = '#{f}';\n")
+ TmpFile.with_file(pre_script) do |script_file|
+ Open.write(f, self.to_s)
+ script = "data_file = '#{f}';\n"
+ script << "script_file = '#{script_file}';\n" if pre_script
+ R.interactive(script)
+ end
end
end
end