Vitalie Spinu
2011-Nov-16 16:18 UTC
[Rd] Injecting source reference from external editors (emacs).
Hi everyone, I would like to inject source reference into R objects from external editor. In my case it's emacs with ESS and ess-tracebug (http://code.google.com/p/ess-tracebug/). Currently the user has to source the file before the src references become available. I would like to spare her, and insert the source references "on-line" during normal interaction (i.e. sending chunks of code from emacs buffers) With new additions in R-14 I started looking into it and discovered that an encapsulation eval(parse(text = "tf <- function(a){a^5 b <- a; return(b) }", srcfile = srcfile("@buffer@"))) does quite a good job, and the debugger would display something like: Browse[2]> debug at @buffer@#2: b <- a Browse[2]> debug at @buffer@#3: return(b) which is great, and could be used for what I want. The problem is that I have to interfere with the user's input, which might not be a good idea always. Is there (will be?) a more direct way of doing this without encapsulation? Currently when a function "tf<-function(a){a^5}" is created at R prompt, R associates with it a srcref with empty srcfile reference. I wonder if it would be possible to instruct R that next evaluation will be from buffer "Xbuf" at line N, something like setSrcSource(srcobject="buffX", srcline=45) so that any input that follows, would get a srcref pointing to "buffX" starting from line 45 instead of just empty reference? At the end of the evaluation I would just reset R with setSrcSource(NULL) Thanks, Vitalie.