is it possible to display plots in an emacs buffer?
rsparapa at post.its.mcw.edu
Fri May 21 19:57:15 CEST 2004
>I've taken this sentence from a recent thread:
>_The usual answer to a question of the form "is it possible to do ....?"
>is "yes, here is how"_
>is it possible to display the plots R makes inside an emacs buffer?
>I hope to get the usual answer... ;-)
>I'll explain the idea a bit more. When I am working in emacs and make a
>plot, a new X11 window opens, I see the plot and to get back to emacs I
>have to close or minimize the X11, I loose quite a lot of time doing
>this every day. Wouldn't it be great if the plots could be displayed
>directly inside an emacs buffer?
>I guess opening an X11 device inside an emacs buffer is not possible (am
>I right?) but other interim solutions would also be great.
> - I can open an image (called say "Rplots.png" or other appropiatte
>format, maybe eps?) in an emacs buffer.
> - Every time I would make a plot in the ESS proccess the output is
>written to this file instead of the default X11 and an automatic call to
>revert-buffer is done in the emacs buffer displaying the image.
> Is it to possible to do this? Has anybody already implemented it?
That's very similar to the way the ESS[SAS] feature used to work. However, in
it's current state it would not do what you want for ESS[R]. So, take the code
below and execute it in the scratch buffer. Then, when you have created a .gif
or .jpg, executing ess-sas-graph-view should bring up the image in it's own
buffer (if you have setup ESS[SAS], then you can just press F12). You can find
out more by reading the info of ESS[SAS].
(defun ess-sas-graph-view ()
"Open a GSASFILE for viewing."
; (ess-sas-goto-log 'no-error-check)
(save-excursion (let ((ess-tmp-sas-graph nil)
(concat "['\"]\\(.*" ess-sas-graph-suffix-regexp "\\)['\"]")))
(search-backward-regexp "[ \t=]" nil t)
(setq ess-tmp-sas-graph (ess-search-except
(if (not ess-tmp-sas-graph)
(setq ess-tmp-sas-graph (ess-search-except ess-tmp-sas-graph-regexp
(setq ess-tmp-sas-graph (read-string "GSASFILE: "
(or ess-tmp-sas-graph ess-sas-file-path)))
; (or ess-tmp-sas-graph (file-name-nondirectory ess-sas-file-path))))
(if (fboundp 'ess-xemacs-insert-glyph) (progn
(if (string-match "[.][gG][iI][fF]" ess-tmp-sas-graph)
(setq ess-tmp-sas-glyph 'gif)
(if (string-match "[.][jJ][pP][eE]?[gG]" ess-tmp-sas-graph)
(setq ess-tmp-sas-glyph 'jpeg)))))
(if ess-tmp-sas-glyph (progn
(switch-to-buffer (file-name-nondirectory ess-tmp-sas-graph))
(make-glyph (vector ess-tmp-sas-glyph :file
(if (and (boundp 'auto-image-file-mode) auto-image-file-mode
(string-match "[.][jJ][pP][eE]?[gG]" ess-tmp-sas-graph))
(insert ess-sas-submit-pre-command " " ess-sas-image-viewer " "
(if (equal ess-sas-submit-method 'sh) " &"))
Rodney Sparapani Medical College of Wisconsin
Sr. Biostatistician Patient Care & Outcomes Research
rsparapa at mcw.edu http://www.mcw.edu/pcor
Was 'Name That Tune' rigged? WWLD -- What Would Lombardi Do
More information about the ESS-help