reddit / emacs

R/ESS plots on macOS

progthw · 2022-07-04 23:03
Hi, I am trying to figure out a good workflow for Emacs + ESS for R. For interactive data analysis it's nice to make a lot of plots and RStudio has a nice panel for these. But ESS, at least by default, uses X, which is not nice: \- plotting happens in the XQuartz application, which means that I need to switch out of Emacs and requires a whole bunch of keypresses and thought that I don't want to deal with; at most a window (or multiple as appropriate) should open which I close it with cmd-w and return to emacs, without having to switch applications. \- plots aren't interactive. In python, for example, you can adjust the plot and save it from the figure window (although the plot window also switches apps and for that reason is not ideal). Is this the standard R plotting workflow on macOS (or for that matter Linux)? How do people handle making a lot of plots, on the fly, using ESS? Any other related workflow tips are also helpful. Thanks.
quantum_mattress · 2022-07-05 03:53
can’t you run a version of emacs using x/xquartz? It’s been a long time but I think I remember doing that.
scbagley · 2022-07-05 12:43
I'm not sure there is a standard. There are options, some of which you have already identified. 1. RStudio works very well and can use emacs-style key bindings. But it's not Emacs. 2. You can put Emacs with R/ESS in one window, and the XQuartz graphics window next to it. Command-leftarrow and Command-rightarrow in the XQuartz window will move through the graphics output history, and you can Command-C to copy and paste into Preview. 3. You can use a graphics device function in R (eg, `pdf()`) to write to a file and view that file in an Emacs buffer next to your source buffer. 4. You can use orgmode, writing your code in a source block that puts the graphics output in a file. Then view graphics output (or the entire document) in an Emacs buffer next to your source buffer.
FreeAd7233 · 2022-07-05 17:36
I recommend you try an r package called httpgd which opens a web browser and your image will be rendered in s host server, it’s interactive and indeed svg. And I recommend you try EAF application framework which can open a web browser inside emacs.
giziti · 2022-07-06 12:18
Would probably rather use R markdown instead of #4.
GlowTurner · 2022-08-31 21:11
>EAF application I'm trying to use your suggestion, but R within emacs is using my desktop firefox, not eaf-browser. What do I need to set to have R use emacs as it's browser? (\`getOption("browser")\` in R returns \`"xdg-open"\`, do I need to set it to something else?)