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.
This commit is contained in:
Eric Schulte 2014-03-23 20:01:37 -06:00
parent dc71b742a9
commit e8112c86ec

View file

@ -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,18 @@ 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
(list (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