From 3805d053a912ede4ae377b22f10c3562ebd4b967 Mon Sep 17 00:00:00 2001 From: "Rainer M. Krug" Date: Tue, 21 Jan 2014 10:35:52 +0100 Subject: [PATCH] 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 --- lisp/ob-R.el | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lisp/ob-R.el b/lisp/ob-R.el index c907d18..62aa7f2 100644 --- a/lisp/ob-R.el +++ b/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 "")))) -- 1.8.3.4 (Apple Git-47)