Q: how can I get ESS (R) to plot directly to an Emacs buffer?
When interacting with R through ESS, R defaults to spawning a separate graphics window outside of Emacs to draw its plots. (One can, of course, choose other graphical devices, which is how we plot to PDF, etc.) Two issues: first, the new window steals focus from Emacs, and second, it sure would be nice to keep everything nice and tidy within the Emacs ecosystem.
So: is there any way to plot "directly" (or even indirectly) to an Emacs buffer and, more importantly, do so without a lot of manual intervention by the user?
There had been some prior discussion in this old Stack Overflow thread, but the partial solutions proposed are not ideal. They mostly involve changing the plotting device in R (say, to PNG), plotting to a temporary file, and then manually visiting that file in an Emacs buffer. That all strikes me as very clunky, especially if the goal is to use the plot window/buffer interactively and draw many plots in a session (or add layers to them on the fly).
I'm speculating here, but it strikes me that, since both R and Emacs support SVG, that might be a useful format to use. However, it's not clear to me if/how one could hook into the R process to communicate on the fly. Is there a way to have R spit SVG code directly into an Emacs buffer, or would it need to go through the intermediary of a temporary file? How could one convince Emacs to visit a new temporary file automagically when R creates it, or update such a plot buffer when the temporary file gets updated/overwritten by a new plot?