[ESS] ess-tracebug under org-mode / babel
spinuvit at gmail.com
Fri Jan 13 17:23:21 CET 2012
On 11 January 2012 14:05, Rainer M Krug <r.m.krug at gmail.com> wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
> I am using org-mode / babel to write my code. Consequently, I am
> editing the org-file and the source code in R code blocks. Then I
> tangle the org file to obtain R code which I then source (or use in a
> package, ...)
> The debugging itself works nicely, but whenever I fix an error in the
> R file, I have to edit it in the org file as well, because otherwise
> the edit will be lost after tangling.
> As I did not manage to get the backward org-babel-detangle) to work, I
> am wondering: is there a way of running the debug with the source
> buffer from org-mode (C-' from the source block) instead of the R file?
> I guess it is tricky?
I am glad you popped this question because it also relates to the
debugging in the sweave files. These files you cannot just source and
alternative mechanism is required.
Already for some time ess-tracebug supports on-the-fly injection of
source references. This basically means that all ess commands
(eval-region, eval-function, etc) can insert source reference of the
evaluated code. These references are used to find the original
location of the code. Thus, the user can work in sweave, org, etc in
the usual way and still have visual debugging working as expected.
By default ess-tracebug automatically injects the source only for
ess-eval-function. The behavior is governed by
ess-tracebug-inject-source-p, which is nil. If you set it to 't' all
the code evaluated *invisibly* will be associated with the source
buffer (be it R, Rnw, or org).
The above works in Rnw files because ess-mode is active in R chunks.
Org-mode has a different approach for managing code and some
elaboration is required. I've just implemented the basic
org-mode/babel integration and it works like a charm.
You don't have to do anything special. Start editing source chunk with
[C-c '], edit the stuff, insert the breakpoint in a function [M-c b]
and eval function as usual ([C-c C-c] or [C-c C-f]). Next time your
func is called, visual debugger will start jumping in the *org src*
buffer. If that buffer has been already closed, the debugger uses the
original .org file to jump through the code in org chunk. Please try.
Unfortunately [C-c C-c] in org-mode (evaluate the chunk) doesn't call
ess-eval-region directly on org buffer, but creates temporary *temp*
buffer and evaluates it. If org-R-babel developers would consider
changing that, you would get automatic srcref insertion directly in
org files by just pressing C-c C-c.
> - --
> Rainer M. Krug, PhD (Conservation Ecology, SUN), MSc (Conservation
> Biology, UCT), Dipl. Phys. (Germany)
> Centre of Excellence for Invasion Biology
> Stellenbosch University
> South Africa
> Tel : +33 - (0)9 53 10 27 44
> Cell: +33 - (0)6 85 62 59 98
> Fax : +33 - (0)9 58 10 27 44
> Fax (D): +49 - (0)3 21 21 25 22 44
> email: Rainer at krugs.de
> Skype: RMkrug
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.11 (GNU/Linux)
> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
> -----END PGP SIGNATURE-----
More information about the ESS-help