emacs-ess / ESS

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

Emacs ESS R and windows 10 #1154

Open Andrzej-Andrzej opened 2 years ago

Andrzej-Andrzej commented 2 years ago

Hi, Can you help me to connect emacs (from Goulet's) to R 4.1 x64 on windows 10. It constantly says it is looking for Rterm. I established a proper PATH ( I think) but errors persists. I would be grateful for help how to do it step by step. I read a tons of tutorials but nothing works.

humanfactors commented 2 years ago

Could you please print the output of echo %path% (from a CMD shell). Also ensure you have rebooted Emacs after setting path, and that there are not trailing \ on path entry.

Andrzej-Andrzej commented 2 years ago

C:\Program Files\R\R-4.1.0\bin\x64\Rterm.exe; C:\Program Files\R\R-4.1.0\bin; c:\Program Files\R\; C:\rtools40\usr\bin; c:\Program Files\R\R-4.0.0\bin\x64;

humanfactors commented 2 years ago

Firstly, you shouldn't need to have C:\Program Files\R\R-4.1.0\bin in your path.

Secondly, you need to have C:\Program Files\R\R-4.1.0\bin\x64 in your path, without the \Rterm.exe.

What is the result of calling Rterm.exe in cmd?

humanfactors commented 2 years ago

I also note that you have an older versions of R in your path which you might want to consider removing.

Andrzej-Andrzej commented 2 years ago

The result of calling Rterm.exe in cmd is as follows: R version 4.1.0 (2021-05-18) -- "Camp Pontanezen" Copyright (C) 2021 The R Foundation for Statistical Computing Platform: x86_64-w64-mingw32/x64 (64-bit)

I have changed it in PATH to: C:\Program Files\R\R-4.1.0\bin\x64

I am so grateful to you because it started working after I rebooted Emacs, thank you very much indeed, I have spent hours on this. My additional questions are as follows if I may:

  1. What about .emacs or _emacs, .emacs.el , init.el files ? Do I need them ? Should I create it ? How to check if I have got them and where are they placed?
  2. So now when I do: install.packages(name of any package) in Emacs, will it be installed to R 4.1 library folder that is showed by .libPaths() so in my case: "C:/Program Files/R/R-4.1.0/library" ?
  3. Do I need to set home directory now in Emacs ?
  4. Emacs finds R now but somehow stops or hangs and I can't write anything in command prompt after > what should I do ?

Thanks again and best regards

mmaechler commented 2 years ago

Andrzej-Andrzej
on Sun, 01 Aug 2021 22:51:00 -0700 writes:

Hi, Can you help me to connect emacs (from Goulet's) to R 4.1 x64 on windows 10. It constantly says it is looking for Rterm. I established a proper PATH ( I think) but errors persists. I would be grateful for help how to do it step by step. I read a tons of tutorials but nothing works.

M-x R stopped working for me also with Windows R, I think because of changes in R-Windows packager setup (not the R sources), but have never cared enough to try finding out.

The workaround has been easy enough though:

M-x R-[Tab]

(where [Tab] is the tabulator key (typically above 'Caps Lock') on your keyboard)

does list all installed R versions (for me) including the "virtual" version 'R-newest' and then I can choose the R version.

M-x R-newest

may also always work (it does for me).

Martin Maechler ETH Zurich and R Core and ESS Core teams

humanfactors commented 2 years ago

@Andrzej-Andrzej see below for answers to your questions

  1. As per https://www.gnu.org/software/emacs/manual/html_node/efaq-w32/Location-of-init-file.html you need to set a user environment variable called HOME, linked to your home folder e.g., C:\Users\Username. If you have a file .emacs.d this will be treated as your init file. Alternatively, you can have a directory .emacs.d\ with the init.el approach.

  2. The default package installation location is not managed by emacs. See https://stackoverflow.com/questions/31707941/how-do-i-change-the-default-library-path-for-r-packages . If you do not want to use the defaults, consider setting an R_LIBS_USER environment variable. Alternatively, configure your .Rprofile.

  3. See point 1.

  4. If you still getting bugs, you can try setting RPATH env variable to C:\Program Files\R\R-4.1.0\bin\x64, but I doubt this will do anything. Instead you will need to report your Emacs version installed, version of ESS, and any config you may have.

Can you execute code from an R buffer, and are you sure the write configuration is set?

Andrzej-Andrzej commented 2 years ago

Thank you very much @humanfactors and @mmaechler I am starting to getting everything to work properly. I wanted to connect Emacs and R as I was not able to get full output from dev version of the package installation in R. This is because of line and characters limits in R console. No such limits I guess in Emacs. https://github.com/r-spatial/sf/issues/1747

humanfactors commented 2 years ago

The alternative could have been to explicitly direct your R output to a file 😊

But anything to encourage Emacs ESS adoption is good news right.

Andrzej-Andrzej commented 2 years ago

The alternative could have been to explicitly direct your R output to a file

How do I do this, because keep_outputs = TRUE doesn't work ?