Class: KnitrRuby::Knitr

Inherits:
OpenStruct
  • Object
show all
Defined in:
lib/knitr-ruby/knitr.rb

Instance Method Summary collapse

Instance Method Details

#knit(content) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
# File 'lib/knitr-ruby/knitr.rb', line 7

def knit(content)
  dir = File.expand_path File.dirname(__FILE__)
  command = "./knitrscript.R --args #{options}"
  Open3::popen3(command, chdir: dir) do |stdin, stdout, stderr, wait_thr|
    stdin.puts content
    stdin.close

    raise StandardError, "Error knitting: #{stderr.read}" if wait_thr.value.exitstatus > 0
    content = stdout.read
  end
end

#optionsObject



19
20
21
22
# File 'lib/knitr-ruby/knitr.rb', line 19

def options
  opts = chunk_options || {}
  opts.map {|k,v| "#{k}=#{v}" }.join(" ")
end