Sha256: 024a647f11f9c56e37ad38a270f7f0f96b2cd265eba54d75bfebc44c34c225f5

Contents?: true

Size: 915 Bytes

Versions: 3

Compression:

Stored size: 915 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, open_options = {})
    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)
      open_options = Misc.add_defaults open_options, :type => :list
      TSV.new(f, open_options)
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
rbbt-util-3.2.1 lib/rbbt/util/R.rb
rbbt-util-3.2.0 lib/rbbt/util/R.rb
rbbt-util-3.1.0 lib/rbbt/util/R.rb