[ESS] request for comments: completion within .R buffers

A.J. Rossini blindglobe at gmail.com
Sun Jun 27 11:12:14 CEST 2010


On Tue, Jun 22, 2010 at 3:19 PM, Stephen Eglen
<S.J.Eglen at damtp.cam.ac.uk> wrote:
> Simon Jackman <jackman at stanford.edu> wrote:
>
>> May I add one more request?
>>
>> I frequently find myself "tweeking" a graph, getting it ready for a slide or a
>> paper etc.  This usually involves re-running non-trivial chunks of R after
>> various edits etc.
>>
>> Could there be a cousin to eval-function that looked backwards for a "pdf(…)"
>> command [or jpeg etc, a command that opens a graphics device] and then forward
>> to a "dev.off()", and then executed the R command in the enclosed region?
>
> I know exactly what you mean, when making figures.
>
> My solution is normally to put all the code that makes a plot into one
> function.
>
> something like
>
> my.pic <- function() {
>  pdf(file="fig.pdf"...)
>  on.exit(dev.off()))
>
>  stuff...
>
> }
>
> and then call my.pic()
>
> ( on.exit(...) is nice as it will close the figure, even if your code in
> "stuff" errors..)
>
> However, for your approach, you could try marking (C-SPC and current
> point) the region you want and then doing C-x n n (narrow-to-region).
> Then C-c C-b will send the whole buffer, which at this time is just your
> code to make the plot.  C-x n w does the "widen" command to remove
> narrowing.
>
> This approach is more general and does not rely on any code to find
> pdf() etc.



Actually, this was what "eval-paragraph" was supposed to solve.  Just
don't have blank lines in the code you want to eval :-),

(at least it worked for me 4 years ago, no time to test right now...)

best,
-tony

blindglobe at gmail.com
Muttenz, Switzerland.
"Commit early,commit often, and commit in a repository from which we
can easily roll-back your mistakes" (AJR, 4Jan05).

Drink Coffee:  Do stupid things faster with more energy!



More information about the ESS-help mailing list