From 838f26c35867e7af0dc46698db41d4df13dfb890 Mon Sep 17 00:00:00 2001 From: Eric Schulte Date: Sun, 23 Mar 2014 20:01:37 -0600 Subject: [PATCH] only wrap R code graphics-file on execution Move this out of the expand-body function so that it is *never* applied to tangled code. --- lisp/ob-R.el | 39 ++++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/lisp/ob-R.el b/lisp/ob-R.el index 62aa7f2..bf7029c 100644 --- a/lisp/ob-R.el +++ b/lisp/ob-R.el @@ -97,24 +97,15 @@ this variable.") "Expand BODY according to PARAMS, return the expanded body." (let ((graphics-file (or graphics-file (org-babel-R-graphical-output-file params)))) - (mapconcat - #'identity - (let ((inside - (append - (when (cdr (assoc :prologue params)) - (list (cdr (assoc :prologue params)))) - (org-babel-variable-assignments:R params) - (list body) - (when (cdr (assoc :epilogue params)) - (list (cdr (assoc :epilogue params))))))) - (if graphics-file - (append - (list (org-babel-R-construct-graphics-device-call - graphics-file params)) - inside - (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"))) + (mapconcat #'identity + (append + (when (cdr (assoc :prologue params)) + (list (cdr (assoc :prologue params)))) + (org-babel-variable-assignments:R params) + (list body) + (when (cdr (assoc :epilogue params)) + (list (cdr (assoc :epilogue params))))) + "\n"))) (defun org-babel-execute:R (body params) "Execute a block of R code. @@ -127,7 +118,17 @@ This function is called by `org-babel-execute-src-block'." (colnames-p (cdr (assoc :colnames params))) (rownames-p (cdr (assoc :rownames params))) (graphics-file (org-babel-R-graphical-output-file params)) - (full-body (org-babel-expand-body:R body params graphics-file)) + (full-body + (let ((inside (org-babel-expand-body:R body params graphics-file))) + (mapconcat #'identity + (if graphics-file + (append + (list (org-babel-R-construct-graphics-device-call + graphics-file params)) + inside + (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"))) (result (org-babel-R-evaluate session full-body result-type result-params -- 1.9.0