Sha256: b1c0b40e8e396726302a17adaf914b3224ad8c17672ad839ddae82fd0515ec32

Contents?: true

Size: 830 Bytes

Versions: 4

Compression:

Stored size: 830 Bytes

Contents

require 'rbbt/util/cmd'
require 'rbbt/util/tsv'

module R

  LIB_DIR = File.join(File.expand_path(File.dirname(__FILE__)),'../../../share/lib/R')
  UTIL    = File.join(LIB_DIR, 'util.R')

  def self.run(command, options = {})
    cmd = "source('#{UTIL}');\n"
    case
    when IO === command
      cmd << command.read
    when File.exists?(command)
      cmd << File.open(command, 'r') do |f| f.read end
    else
      cmd << command
    end

    Log.debug "R Script:\n#{ cmd }"

    CMD.cmd('R --vanilla --slave --quiet', options.merge(:in => cmd))
  end

end

class TSV
  def R(script)
    TmpFile.with_file do |f|
      Open.write(f, self.to_s)
      Log.debug(R.run(
      <<-EOF
data = rbbt.tsv('#{f}');
#{script.strip}
rbbt.tsv.write('#{f}', data);
      EOF
      ).read)
      TSV.new(f, :type => :list)
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
rbbt-util-3.0.3 lib/rbbt/util/R.rb
rbbt-util-3.0.2 lib/rbbt/util/R.rb
rbbt-util-2.1.0 lib/rbbt/util/R.rb
rbbt-util-2.0.1 lib/rbbt/util/R.rb