[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, 23 Mar 2014 20:03:39 -0600 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (gnu/linux) |
Rainer M Krug <address@hidden> writes:
> Eric Schulte <address@hidden> writes:
>
>> Charles Berry <address@hidden> writes:
>>
>>> John Hendy <jw.hendy <at> gmail.com> writes:
>>>
>>> [deleted]
>>>> >
>>>> > I think the default behavior should be reverted, as tangling and
>>>> > exporting are two different things. When I tangle, I want to see the
>>>> > code blocks as they are in the org document (with possible variables and
>>>> > expansions) but not to create files where I do not put it explicitly
>>>> > into a code block. These wrappers have nothing to do with the code, and
>>>> > are only there for the exported engine. So I would either revert to the
>>>> > original behavior, or, introduce a new header argument,
>>>> > e.g. :include-wrappers, which would, if set to t, include the export
>>>> > wrappers in the tangled file. This might be useful for debugging
>>>> > exporting of code block results, but not for general tangling.
>>>>
>>>> Thanks for chiming in. This was my gut reaction to the default
>>>> behavior. I guess we're still only a sample size of 2, but
>>>> intuitively, I would think that tangling would be a separate beast in
>>>> most cases from exporting. Just to have it on the record, if I tangle,
>>>> it's usually to take the code I've used in something like a Beamer
>>>> presentation or document and combine it into a single .R file so
>>>> someone can run it without needing Org-mode.
>>>
>>> [deleted]
>>>
>>> Sorry to be late to add my $0.02...
>>>
>>> I never want the try/catch wrappers.
>>>
>>> But noweb is indispensable.
>>>
>>> I use noweb a lot to organize and collect blocks. In some cases, I export
>>> them and in others I just tangle them.
>>>
>>> I hope that the revised code will allow me to turn off try/catch wrapping
>>> and still be able to use noweb when tangling or exporting.
>>>
>>
>> In addition to noweb, there are cases where variable expansion is useful
>> in tangled code.
>>
>> The simplest option is to move things like try/catch blocks out of the
>> code block expansion function, and into the execution function. Then if
>> other language present similar constructs (which we want to add to
>> execution by default but never want to tangle), we can think about
>> abstracting this out into some new level of code block expansion.
>>
>> Thoughts?
>
> Makes perfect sense to me, and would definitely be the better place to
> add them.
>
> If one wants enclosing code in the tangling, there is always
> the :epilogue and :prologue header arguments, and the try/catch should
> be considered as internal to the execution.
>
Great, how's this patch work? If it looks good I'll apply it.
Thanks,
>From 838f26c35867e7af0dc46698db41d4df13dfb890 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 | 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
--
Eric Schulte
https://cs.unm.edu/~eschulte
PGP: 0x614CA05D
- Re: [O] [BABEL] BUG Re: Omitting try/catch blocks from tangled R code?, John Hendy, 2014/03/11
- Re: [O] [BABEL] BUG Re: Omitting try/catch blocks from tangled R code?, Eric Schulte, 2014/03/17
- Re: [O] [BABEL] BUG Re: Omitting try/catch blocks from tangled R code?, John Hendy, 2014/03/17
- Re: [O] [BABEL] BUG Re: Omitting try/catch blocks from tangled R code?, Eric Schulte, 2014/03/17
- Re: [O] [BABEL] BUG Re: Omitting try/catch blocks from tangled R code?, Rainer M Krug, 2014/03/18
- Re: [O] [BABEL] BUG Re: Omitting try/catch blocks from tangled R code?, John Hendy, 2014/03/18
- Re: [O] [BABEL] BUG Re: Omitting try/catch blocks fro m tangled R code?, Charles Berry, 2014/03/19
- Re: [O] [BABEL] BUG Re: Omitting try/catch blocks from tangled R code?, Eric Schulte, 2014/03/20
- Re: [O] [BABEL] BUG Re: Omitting try/catch blocks from tangled R code?, Rainer M Krug, 2014/03/20
- Re: [O] [BABEL] BUG Re: Omitting try/catch blocks from tangled R code?,
Eric Schulte <=
- Re: [O] [BABEL] BUG Re: Omitting try/catch blocks from tangled R code?, Rainer M Krug, 2014/03/24
- Re: [O] [BABEL] BUG Re: Omitting try/catch blocks from tangled R code?, Eric Schulte, 2014/03/24
- Re: [O] [BABEL] BUG Re: Omitting try/catch blocks from tangled R code?, Rainer M Krug, 2014/03/25
- Re: [O] [BABEL] BUG Re: Omitting try/catch blocks from tangled R code?, Eric Schulte, 2014/03/27
- Re: [O] [BABEL] BUG Re: Omitting try/catch blocks from tangled R code?, Rainer M Krug, 2014/03/28
- Re: [O] [BABEL] BUG Re: Omitting try/catch blocks from tangled R code?, Rainer M Krug, 2014/03/28
- Re: [O] [BABEL] BUG Re: Omitting try/catch blocks from tangled R code?, Eric Schulte, 2014/03/30
- Re: [O] [BABEL] BUG Re: Omitting try/catch blocks from tangled R code?, Rainer M Krug, 2014/03/31