emacs-ess / ESS

Emacs Speaks Statistics: ESS
https://ess.r-project.org/
GNU General Public License v3.0
614 stars 160 forks source link

error when C-c ' on an org-src R block #1184

Closed japhir closed 2 years ago

japhir commented 2 years ago

After just updating to the newest git version (ess-version: 18.10.3snapshot [<unknown>] (loaded from /home/japhir/.emacs.d/elpa/ess-20220127.1454/) I now get the following errors when I C-c ' on an org-mode #+begin_src R code block:

Messages while loading ESSR: + + + Error in file(filename, "r", encoding = encoding) : 
  cannot open the connection
In addition: Warning message:
In file(filename, "r", encoding = encoding) :
  cannot open file ’/home/japhir/.emacs.d/elpa/ess-20220127.1454/etc/ESSR/R/.load.R’: No such file or directory

This hangs until I C-g, but the R process is started. Every time I try it seems to start a new *R:2:project_name* buffer for a file that has #+PROPERTY: header-args:R :session *R:project_name* :exports both :results output :eval no-export

Perhaps this has to do with my ess config hook? I forgot why I had added it, but it was a workaround a while ago.

japhir commented 2 years ago

disabling the second hook in my use-package call does make this work again!

(use-package ess
   :hook ( ;; first hook here
           ;; remove below hook
           (ess-r-post-run . (lambda ()
                (ess-load-file (make-temp-file nil nil nil
                                     "Sys.setenv(\"DISPLAY\"=\":0.0\")")
vspinu commented 2 years ago

So, considered fixed?

japhir commented 2 years ago

Oh yeah sorry, forgot to close this. I couldn't find anywhere in my notes why I had added that hook in the first place, so I guess we'll never know ;-). Thanks!

japhir commented 2 years ago

Ah, I think that fix had something to do with opening up a cairo or x11 device on wayland! Because if I open a new R session from emacs now, (M-x R) and run x11() I get the following warning:

Error in .External2(C_X11, d$display, d$width, d$height, d$pointsize,  : 
  unable to start device X11cairo
In addition: Warning message:
In x11() : unable to open connection to X11 display ''

If I manually run, from within the R session:

Sys.setenv("DISPLAY" = ":0.0")

and then try to run x11() again, it opens up a blank x11 display as desired.

Do you have any idea how to add this hook without breaking the C-c ' behaviour?

japhir commented 2 years ago

I've just tested it using with-emacs.sh -i ess to see if it was something in my config, and there it works perfectly, so it must be something I'm doing wrong in my config. It could have something to do with my (setq inferior-R-args "--no-restore-history --no-save")?

EDIT: it's defintely not something in my ess config because when I call with-emacs.sh -i ess -i use-package and copy my config to the scratch buffer and execute it, everything works as expected. So this is likely not an ess issue but an "I shot myself in the foot with a >2500 line config file". I'll close this again but am still very open to feedback on what might be the issue :)

vspinu commented 2 years ago

It could have something to do with my (setq inferior-R-args "--no-restore-history --no-save")?

Should not be.

japhir commented 2 years ago

I've just added the Sys.setenv("DISPLAY" = ":0.0") call to my ~/.Rprofile, this seems to fix the issue for me :)