Ver código fonte

Graphic: Catch errors and return error message

* lisp/ob-R.el (org-babel-expand-body:R): Added the opening of the
  tryCatch() wrapper

* lisp/ob-R.el (org-babel-R-construct-graphics-device-call): Added
  closing of the wrapper containing the error function.

Added tryCatch() wrapper around the execution of the source block so
that if an error occurs
- the R graphic device is closed even when an error occurs
- a graph containing the error message is created
- the error message is printed in the R session in the form
    ERROR : the error message

TINYCHANGE
Rainer M. Krug 11 anos atrás
pai
commit
eaa3a761da
1 arquivos alterados com 2 adições e 2 exclusões
  1. 2 2
      lisp/ob-R.el

+ 2 - 2
lisp/ob-R.el

@@ -112,7 +112,7 @@ this variable.")
             (list (org-babel-R-construct-graphics-device-call
                    graphics-file params))
             inside
-            (list "dev.off()"))
+            (list "},error=function(e){plot(x=-1:1, y=-1:1, type='n', xlab='', ylab='', axes=FALSE); text(x=0, y=0, labels=e$message, col='red'); paste('ERROR', e$message, sep=' : ')}); dev.off()"))
          inside))
      "\n")))
 
@@ -295,7 +295,7 @@ Each member of this list is a list with three members:
 			      (substring (symbol-name (car pair)) 1)
 			      (cdr pair)) ""))
 		params ""))
-    (format "%s(%s=\"%s\"%s%s%s)"
+    (format "%s(%s=\"%s\"%s%s%s); tryCatch({"
 	    device filearg out-file args
 	    (if extra-args "," "") (or extra-args ""))))