开发者

Pop-up windows in R & Emacs

开发者 https://www.devze.com 2023-02-11 06:34 出处:网络
I am using ESS in order to stay in Emacs when working with R. Whenever I create a plot a new pop-up appears with the graph. This new window seems to be a part of the R process called inside Emacs. As

I am using ESS in order to stay in Emacs when working with R. Whenever I create a plot a new pop-up appears with the graph. This new window seems to be a part of the R process called inside Emacs. As such the new window is not part of the buffer-list and seems to lie outside the Emacs environment.

Can a new window created by R, containing e.g. graphs called by plot() or respective functions in ggplot2/lattice, be forced to sta开发者_Go百科y inside the Emacs environment? So that the plot is available as a new buffer.

Thanks!


Oh yes it can...

In ESS, do this:

png(file="tmp.png")
plot(1:10)
dev.off()
# [[tmp.png]]

Nothing. Now do ESC X iimage-mode (yes, two i's there).

This puts your buffer into iimage minor mode, it should spot the [[tmp.png]] and load your image in there. This should be easily automatable. This is the first time I've discovered this for myself so there's probably better ways to do it.

There's clearly been some chatter on the ESS list about this:

https://stat.ethz.ch/pipermail/ess-help/2009-August/005474.html

but I am surprised its not in the ESS core yet...


No, sorry, it cannot. Emacs buffers are text. Graphics windows are graphics devices.

But you can do this yourself. Before plotting, or even at the begin of a session, say

pdf(file="/tmp/myplotfile.pdf")

and now plots will go there. You can then open the pdf file in Emacs, and recent versions include a pdf preview inside Emacs (at least on my Linux boxen, not sure if I needed extra modes for that). That would come close to your requirements.


This does not exactly answer the OP's question because this goes outside of ESS but it still may be relevant to some because it still relates to using R to generate graphics that can be viewed inside of Emacs.

You can do this using Emacs iPython Notebook (ein). You have to set up Jupyter first but after that it's pretty straightforward and can work with different kernels (R, Python, Julia, etc.). Below is a screenshot

Pop-up windows in R & Emacs


This is unlikely to be the solution you are looking for as it involves turning Emacs into a window manager (works for Linux and MacOS): the package EXWM (Emacs X Window Manager) is a full-featured tiling window manager that turns all X windows into Emacs buffers.

Here is an example of what that would look like (note the R Graphics window on the right which is now an Emacs buffer):

Pop-up windows in R & Emacs

This allows you to use Emacs keybindings, configuration, etc. to all X windows.


try this:

X11()   #  starts a X11 graphics device
plot(c(1:10),c(1:10))
savePlot(filename = "try_save_X11.png",type = c("png"))
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号