[ESS] Automatically pasting R output into script buffer?
Yihui Xie
xie at yihui.name
Fri Oct 14 16:12:47 CEST 2011
Just in case you are interested: there is a function tidy.eval() in
the formatR package which I believe is doing the same thing as you
described, except that it is not implemented in Emacs. I'm not quite
in favor of inserting output into the *original* R script; instead, I
recommend to keep the original script, use
tidy.eval('original-script.R') to get a readable output and pass it to
whoever wants to read it.
See the 4th section in this page for examples:
https://github.com/yihui/formatR/wiki
I'm thinking of adding a feature of highlighting the code and writing
into an HTML page like the Pretty R provided by Revolution Analytics:
http://www.inside-r.org/pretty-r
Regards,
Yihui
--
Yihui Xie <xieyihui at gmail.com>
Phone: 515-294-2465 Web: http://yihui.name
Department of Statistics, Iowa State University
2215 Snedecor Hall, Ames, IA
On Fri, Oct 14, 2011 at 8:54 AM, Vitalie Spinu <spinuvit.list at gmail.com> wrote:
> Hi Aloke,
>
> Next will do what you want. If selection is active it sends the whole
> region, otherwise the current line only.
>
>
> (defun ess-eval-line-or-region-in-place ()
> "Runction for evaluating a region or line (depending whether it is a
> selectio ni nthe buffer."
> (interactive)
> (let ((buf (get-buffer-create " *ess-command-output*")))
> (if (not (and transient-mark-mode mark-active))
> ;; execute current line
> (ess-command (format "\n%s\n" (buffer-substring
> (point-at-bol) (point-at-eol))) buf)
> ;; else - execute region
> (ess-command (format "\n%s\n" (buffer-substring (mark) (point))) buf)
> (setq mark-active nil)
> (goto-char (max (mark) (point)))
> )
> (with-current-buffer buf
> (goto-char (point-min))
> (while (re-search-forward "^" nil t)
> (insert "## ")))
> (set-mark (point) )
> (end-of-line)
> (insert "\n")
> (insert-buffer-substring buf)
> (forward-line)
> ))
>
>
> (define-key ess-mode-map [(control ?c) (control ?j)]
> 'ess-eval-line-or-region-in-place)
>
> Cheers,
> Vitalie.
>
>
> O Fri, Oct 14, 2011 at 11:03 AM, Aloke Phatak <Aloke.Phatak at csiro.au> wrote:
>> On 14/10/2011 4:38 PM, Stephen Eglen wrote:
>>>
>>> Aloke Phatak<Aloke.Phatak at csiro.au> wrote:
>>>
>>>> [...] 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. [...] Would you
>>
>>> have the output commented?
>>
>> Yes, sorry, I should have been more precise, the output would be commented.
>> The resulting file *could* be used as a script file, but I tend to use such
>> files for documenting analyses that I've done - sort of like a text-based,
>> poor-man's version of Sweave. I do use Sweave, but for quickly documenting
>> an analysis for future reference or to pass on to colleagues, I prefer a
>> heavily-commented transcript file.
>>
>>> 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)
>>> range(x)
>>> #+end_src
>>>
>>> and then hit C-c C-c within that chunk; you should then get:
>>> #+results:
>>> : [1] 1 8
>>>
>>> My ESS tutorial this year gives the relevant background.
>>> http://www.damtp.cam.ac.uk/user/sje30/ess11
>>
>> Looks interesting already!
>>
>> Aloke
>>
>> ______________________________________________
>> ESS-help at r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/ess-help
>>
>
> ______________________________________________
> ESS-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/ess-help
>
More information about the ESS-help
mailing list