瀏覽代碼

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.
Eric Schulte 11 年之前
父節點
當前提交
e8112c86ec
共有 1 個文件被更改,包括 21 次插入19 次删除
  1. 21 19
      lisp/ob-R.el

+ 21 - 19
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,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