[ESS] Automatically pasting R output into script buffer?

Stephen Eglen S.J.Eglen at damtp.cam.ac.uk
Fri Oct 14 10:38:51 CEST 2011

Aloke Phatak <Aloke.Phatak at csiro.au> wrote:

> I use ESS/R in two-buffer mode - a script buffer where I'm working on
> an R script, and the other, an R process buffer. I'd like to be able
> to execute a command from the script buffer (using C-c C-j, for
> example) and have its output pasted into my script directly below the
> command I've just executed.
> Is that possible?

I don't think its possible with ESS as-is.  One problem with your
approach is that the script will then have a mix of code and output, so
you can't then run the script again as a whole without getting errors.
Would you have the output commented?

> Right now, I have to switch to the R process buffer, copy the output,
> and then paste it back into my script buffer.

you might want to take a look at org-babel for this.  It does more than
what you want, but e.g. you can have chunks like this in an R buffer:

#+begin_src R :results output
  x <- rbinom(100, 10, 0.5)

and then hit C-c C-c within that chunk; you should then get:
: [1] 1 8

My ESS tutorial this year gives the relevant background.


More information about the ESS-help mailing list