[ESS] insert result in the current buffer?

Sam Steingold sds at gnu.org
Wed Aug 29 21:31:03 CEST 2012


> * Vitalie Spinu <fcvahivg at tznvy.pbz> [2012-08-29 21:15:41 +0200]:
>
> I also think org-mode is the best for this type of things. 
>
>   >> Stephen Eglen <S.J.Eglen at damtp.cam.ac.uk>
>   >> on Wed, 29 Aug 2012 19:29:15 +0100 wrote:
>
>   >> my usual workflow is to keep everything I ever type in a file-bound
>   >> buffer and send stuff to the *R* buffer using C-c C-p or C-c C-j.
>   >> sometimes I want to copy the result from *R* to the current buffer.
>
> Why not C-c C-c or C-M-x, faster and more powerful (especially from
> today, check the HEAD:) ).

will do.

>   >> 1. a separate command which would send stuff to *R* and then copy *R*
>   >> output into the current buffer OR
>   >> 
>   >> 2. C-u before an eval command would do that OR
>   >> 
>   >> 3. a separate command which would copy the last output from *R* into the
>   >> current buffer
>   >> 
>   >> Any chance this is already available?
>
> This has been asked before. Back then I wrote a quick lisp. May be
> it's good to include it in ESS?

absolutely.

> (defun ess-eval-line-or-region-in-place ()

"in-place"?
I think I would be able to find this function easier if it were called
similar to "C-j runs the command eval-print-last-sexp" or contained
"insert" in its name.

>   (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)
>     ))

34
## > [1] 34
##
exp(5)
## > [1] 148.4132
##
rnorm(10)
## >  [1] -0.1301504  1.3798667  1.1376690  0.3506802 -0.6732953  0.2450176
##  [7] -1.6418130 -0.9848614  0.2139489  1.4596419
##

problems:

1. extra commented line
2. "> " prefix

Actually, I would much prefer my 3rd option because it allows me a
margin of error: I can modify the code until I am happy with the output
and then collect it with one command without having to re-evaluate it.

thanks!

-- 
Sam Steingold (http://sds.podval.org/) on Ubuntu 12.04 (precise) X 11.0.11103000
http://www.childpsy.net/ http://jihadwatch.org http://openvotingconsortium.org
http://www.memritv.org http://camera.org http://honestreporting.com
MS: Brain off-line, please wait.



More information about the ESS-help mailing list