parameters: (code, *args, **kwds)
docstring: Run a block of R code.
  
      EXAMPLES::
  
           sage: print r.eval("summary(c(1,2,3,111,2,3,2,3,2,5,4))")   # outputs a string
           Min. 1st Qu.  Median    Mean 3rd Qu.    Max.
           1.00    2.00    3.00   12.55    3.50  111.00
  
      In the notebook, you can put %r at the top of a cell, or type "%default_mode r" into
      a cell to set the whole worksheet to r mode.
  
      NOTE: Any plots drawn using the plot command should "just work", without having
      to mess with special devices, etc.
docstring_summary: Run a block of R code.
docstring_tokens: Run a block of R code .
function: def r_eval(code, *args, **kwds):
      """
      Run a block of R code.
  
      EXAMPLES::
  
           sage: print r.eval("summary(c(1,2,3,111,2,3,2,3,2,5,4))")   # outputs a string
           Min. 1st Qu.  Median    Mean 3rd Qu.    Max.
           1.00    2.00    3.00   12.55    3.50  111.00
  
      In the notebook, you can put %r at the top of a cell, or type "%default_mode r" into
      a cell to set the whole worksheet to r mode.
  
      NOTE: Any plots drawn using the plot command should "just work", without having
      to mess with special devices, etc.
      """
      # Only use special graphics support when using r as a cell decorator, since it has
      # a 10ms penalty (factor of 10 slowdown) -- which doesn't matter for interactive work, but matters
      # a lot if one had a loop with r.eval in it.
      if sage.interfaces.r.r not in salvus.code_decorators:
          return r_eval0(code, *args, **kwds)
  
      global r_dev_on
      if r_dev_on:
          return r_eval0(code, *args, **kwds)
      try:
          r_dev_on = True
          tmp = '/tmp/' + uuid() + '.svg'
          r_eval0("svg(filename='%s')"%tmp)
          s = r_eval0(code, *args, **kwds)
          r_eval0('dev.off()')
          return s
      finally:
          r_dev_on = False
          if os.path.exists(tmp):
              salvus.stdout('\n'); salvus.file(tmp, show=True); salvus.stdout('\n')
              os.unlink(tmp)
function_tokens: def r_eval ( code , * args , * * kwds ) : # Only use special graphics support when using r as a cell decorator, since it has # a 10ms penalty (factor of 10 slowdown) -- which doesn't matter for interactive work, but matters # a lot if one had a loop with r.eval in it. if sage . interfaces . r . r not in salvus . code_decorators : return r_eval0 ( code , * args , * * kwds ) global r_dev_on if r_dev_on : return r_eval0 ( code , * args , * * kwds ) try : r_dev_on = True tmp = '/tmp/' + uuid ( ) + '.svg' r_eval0 ( "svg(filename='%s')" % tmp ) s = r_eval0 ( code , * args , * * kwds ) r_eval0 ( 'dev.off()' ) return s finally : r_dev_on = False if os . path . exists ( tmp ) : salvus . stdout ( '\n' ) salvus . file ( tmp , show = True ) salvus . stdout ( '\n' ) os . unlink ( tmp )