Class: RC
- Inherits:
-
Object
show all
- Defined in:
- lib/util/exec_ruby.rb
Overview
Class RC is used only as a context for all ruby chunks in the rmarkdown file.
This allows for chunks to access local variables defined in other chunks.
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize ⇒ RC
Returns a new instance of RC.
36
37
38
|
# File 'lib/util/exec_ruby.rb', line 36
def initialize
@out_list = R.list
end
|
Instance Attribute Details
#out_list ⇒ Object
Returns the value of attribute out_list.
34
35
36
|
# File 'lib/util/exec_ruby.rb', line 34
def out_list
@out_list
end
|
Instance Method Details
#get_binding ⇒ Object
66
67
68
|
# File 'lib/util/exec_ruby.rb', line 66
def get_binding
binding
end
|
#normalize_output_arg(arg) ⇒ Object
In gknit, stdout is redirected to StringIO. Under JRuby, Kernel.puts can treat
R::Vector as array-like (to_ary) and print one element per line. Normalize R
objects to their R printed form first, so puts vec matches gstudio ([1] ...).
47
48
49
50
51
|
# File 'lib/util/exec_ruby.rb', line 47
def normalize_output_arg(arg)
return arg.to_s if arg.is_a?(::R::Object)
return arg.map { |item| normalize_output_arg(item) } if arg.is_a?(::Array)
arg
end
|
#outputs(obj) ⇒ Object
40
41
42
|
# File 'lib/util/exec_ruby.rb', line 40
def outputs(obj)
@out_list = R.c(@out_list, obj)
end
|
#print(*args) ⇒ Object
58
59
60
|
# File 'lib/util/exec_ruby.rb', line 58
def print(*args)
::Kernel.print(*args.map { |arg| normalize_output_arg(arg) })
end
|
#puts(*args) ⇒ Object
53
54
55
56
|
# File 'lib/util/exec_ruby.rb', line 53
def puts(*args)
return ::Kernel.puts if args.empty?
::Kernel.puts(*args.map { |arg| normalize_output_arg(arg) })
end
|
#reset_outputs ⇒ Object
62
63
64
|
# File 'lib/util/exec_ruby.rb', line 62
def reset_outputs
@out_list = nil
end
|