Method: RinRuby#echo

Defined in:
lib/rinruby.rb

#echo(enable = nil, stderr = nil) ⇒ Object

The echo method controls whether the eval method displays output from R and, if echo is enabled, whether messages, warnings, and errors from stderr are also displayed.

Parameters that can be passed to the eval method

  • enable: Setting enable to false will turn all output off until the echo command is used again with enable equal to true. The default is nil, which will return the current setting.

  • stderr: Setting stderr to true will force messages, warnings, and errors from R to be routed through stdout. Using stderr redirection is typically not needed for the C implementation of Ruby and is thus not not enabled by default for this implementation. It is typically necessary for jRuby and is enabled by default in this case. This redirection works well in practice but it can lead to interleaving output which may confuse RinRuby. In such cases, stderr redirection should not be used. Echoing must be enabled when using stderr redirection.



485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
# File 'lib/rinruby.rb', line 485

def echo(enable=nil,stderr=nil)
  if ( enable == false ) && ( stderr == true )
    raise "You can only redirect stderr if you are echoing is enabled."
  end
  if ( enable != nil ) && ( enable != @echo_enabled )
    echo(nil,false) if ! enable
    @echo_enabled = ! @echo_enabled
  end
  if @echo_enabled && ( stderr != nil ) && ( stderr != @echo_stderr )
    @echo_stderr = ! @echo_stderr
    if @echo_stderr
      eval "sink(stdout(),type='message')"
    else
      eval "sink(type='message')"
    end
  end
  [ @echo_enabled, @echo_stderr ]
end