emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [O] [BABEL] BUG Re: Omitting try/catch blocks from tangled R code?


From: Eric Schulte
Subject: Re: [O] [BABEL] BUG Re: Omitting try/catch blocks from tangled R code?
Date: Sun, 30 Mar 2014 08:19:37 -0600
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.4.50 (gnu/linux)

>
> Apologies - I am still struggling with encryption......
>
> So here is my example:
>
> --8<---------------cut here---------------start------------->8---
> #+TITLE: single_to_multi
> #+DATE: <2013-10-15 Tue>
> #+AUTHOR: Rainer M. Krug
> #+EMAIL: address@hidden
>
> ≈* Load R packages and data
> #+BEGIN_SRC R
> cat("Loading Data\n")
> #+END_SRC
> --8<---------------cut here---------------end--------------->8---
>
> I am using only org loaded and R enabled.
>
> C-c C-c on the block produces the error
>
> emacs version: 
> GNU Emacs 24.3.1 (x86_64-apple-darwin13.0.0, Carbon Version 1.6.0
> AppKit 1265) of 2014-02-13 on Rainers-MacBook-Pro-2.local
>
> org version:
> Org-mode version 8.2.5h (release_8.2.5h-837-gb296cc @
> /Users/rainerkrug/.emacs.d/org-mode/lisp/)
>

Thanks, a fixed version of the patch is attached.  If this works please
let me know and I'll apply.

Best,

>From d67248db79faf19e1bdcac0230c37670b6115bdd Mon Sep 17 00:00:00 2001
From: Eric Schulte <address@hidden>
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 | 40 +++++++++++++++++++++-------------------
 1 file changed, 21 insertions(+), 19 deletions(-)

diff --git a/lisp/ob-R.el b/lisp/ob-R.el
index 62aa7f2..780d99f 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,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
-- 
1.9.1

-- 
Eric Schulte
https://cs.unm.edu/~eschulte
PGP: 0x614CA05D

reply via email to

[Prev in Thread] Current Thread [Next in Thread]