From 559a339db955f358a78574b764a87ae7f9a8ad06 2013-07-01 04:36:43 From: Brian E. Granger Date: 2013-07-01 04:36:43 Subject: [PATCH] Merge pull request #3481 from takluyver/rmagic-nicer-errors Display R errors without Python traceback --- diff --git a/IPython/extensions/rmagic.py b/IPython/extensions/rmagic.py index ff592e8..537ffa7 100644 --- a/IPython/extensions/rmagic.py +++ b/IPython/extensions/rmagic.py @@ -578,16 +578,24 @@ class RMagics(Magics): self.r('png("%s/Rplots%%03d.png",%s)' % (tmpd.replace('\\', '/'), png_args)) text_output = '' - if line_mode: - for line in code.split(';'): - text_result, result = self.eval(line) + try: + if line_mode: + for line in code.split(';'): + text_result, result = self.eval(line) + text_output += text_result + if text_result: + # the last line printed something to the console so we won't return it + return_output = False + else: + text_result, result = self.eval(code) text_output += text_result - if text_result: - # the last line printed something to the console so we won't return it - return_output = False - else: - text_result, result = self.eval(code) - text_output += text_result + + except RInterpreterError as e: + print(e.stdout) + if not e.stdout.endswith(e.err): + print(e.err) + rmtree(tmpd) + return self.r('dev.off()')