From mboxrd@z Thu Jan 1 00:00:00 1970 From: Eric Schulte Subject: Re: [BABEL] BUG Re: Omitting try/catch blocks from tangled R code? Date: Sun, 30 Mar 2014 08:19:37 -0600 Message-ID: <87fvlzg45i.fsf@gmail.com> References: <52F498AE.6090802@krugs.de> <87siruamo3.fsf@gmail.com> <52F5326C.7010505@krugs.de> <877g7syio6.fsf@gmail.com> <87txawwwh6.fsf@gmail.com> <87r45xeabf.fsf@gmail.com> <87fvm8gxok.fsf@gmail.com> <87siq7g2j5.fsf@gmail.com> <87d2h71qqc.fsf@bagel.gateway.pace.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:59229) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WUGaQ-0003kf-1e for emacs-orgmode@gnu.org; Sun, 30 Mar 2014 10:19:50 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WUGaL-0000qS-AY for emacs-orgmode@gnu.org; Sun, 30 Mar 2014 10:19:45 -0400 Received: from mail-pd0-x22b.google.com ([2607:f8b0:400e:c02::22b]:42610) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WUGaK-0000qN-Ss for emacs-orgmode@gnu.org; Sun, 30 Mar 2014 10:19:41 -0400 Received: by mail-pd0-f171.google.com with SMTP id r10so6855357pdi.16 for ; Sun, 30 Mar 2014 07:19:40 -0700 (PDT) In-Reply-To: (Rainer M. Krug's message of "Fri, 28 Mar 2014 09:51:09 +0100") List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Rainer M Krug Cc: emacs-orgmode@gnu.org, Charles Berry --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable > > 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: Rainer@krugs.de > > =E2=89=88* 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:=20 > 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, --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=0001-only-wrap-R-code-graphics-file-on-execution.patch >From d67248db79faf19e1bdcac0230c37670b6115bdd 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 | 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 --=-=-= Content-Type: text/plain -- Eric Schulte https://cs.unm.edu/~eschulte PGP: 0x614CA05D --=-=-=--