jalvesaq / Nvim-R

Vim plugin to work with R
GNU General Public License v2.0
968 stars 125 forks source link

Cannot find r_path after setting R_path and R_app in .vimrc #757

Closed alejandrohagan closed 1 year ago

alejandrohagan commented 1 year ago

Hi!

First thank you for your plugin ! I love it.

I am currently using git bash version of linux on my windows computer using vim (See below for versions).

I am trying to get your plugin to work and believe I've followed all the instructions but I can't get it to work. Specifically after running :message I get the below read out

R executable not found: '/c/'Program Files'/R/R-4.2.3/bin/R.exe'
ERROR: R exit code = 122! Please, run :RDebugInfo for details.
"/c/'Program Files'/R/R-4.2.3/bin/R" is not a directory. Fix the value of R_path in your vimrc.
"/c/'Program Files'/R/R-4.2.3/bin/R.exe" not found. Fix the value of either R_path or R_app in your vimrc.

Check RDebugInfo

RInitOut
RInitErr
executing job failed: No such file or directory

However when I run that same R_path file in bash it will successfully open up R in my terminal.

Any thoughts?

version info below

VIM - Vi IMproved 9.0 (2022 Jun 28, compiled Feb 11 2023 19:56:29)
Included patches: 1-1302
Compiled by <https://www.msys2.org/>
jalvesaq commented 1 year ago

The single quotes around 'Program Files' might be the problem. The directory name is "/c/Program Files/R/R-4.2.3/bin/R", not "/c/'Program Files'/R/R-4.2.3/bin/R".

alejandrohagan commented 1 year ago

hi!

Thank you for that -- it fixed the issue in that I am no longer getting error code 122 however I now getting error code 1, please see print out below from :RDebugInfo

RInitOut
RInitErr
Error in utils::installed.packages()["nvimcom", c("Version", "LibPath",  :
  subscript out of bounds
Calls: unname
Execution halted
jalvesaq commented 1 year ago

I added two more error checks to R/before_ncs.R. Could you update Nvim-R and try again, please?

alejandrohagan commented 1 year ago

thank you!

I get the below error after updating the pluing in

RInit Warning
nvimcom is not installed.
RInitOut
RInitErr
jalvesaq commented 1 year ago

You should see the RInit Warning "nvimcom is no installed." (with a dot at the end) if the nvimcom directory is not part of Nvim-R directory. More specifically, if the file Nvim-R/R/nvimcom/DESCRIPTION is not found.

alejandrohagan commented 1 year ago

Upon opening up a new R file after a few movements I do see the error / warning below that says "nvimcon is not installed."

Do I need to use a different plugin manager? or install a package?

jalvesaq commented 1 year ago

I don't know what you should do because I don't have access to a Windows machine and you are using MSYS2 on Windows.

The problem is in this line of R/before_ncs.R:

if (file.exists(paste0(nvim_r_home, "/R/nvimcom/DESCRIPTION"))) {

On Linux, if the DESCRIPTION file is not found it is because it simply is not there. But in your case, the nvim_r_home path might be wrong, as the R_path was. Nvim-R is not prepared to translate Windows' paths into MSYS2 ones. The value of nvim_r_home is defined in R/start_ncs.vim as:

    let flines = ['nvim_r_home <- "' . g:rplugin.home . '"',

So, you can know its value with the following command:

:echo g:rplugin.home
alejandrohagan commented 1 year ago

okay -- interesting. It seems to be an issue where in "linux" my path is /c/some/file/path and that works when I am in linux but when if I want to use R in linux (eg. just running R executable file in the command line) I need to write my filepath like windows eg. C:/some/file/path

So the top line you pasted (below) is producing the file path in linux "language" for file paths but when this gets evaluated in R it evaluates to false because it is expecting the file path to be in windows "language" for file paths

if (file.exists(paste0(nvim_r_home, "/R/nvimcom/DESCRIPTION")))

I tried to hardcode the windows version of the file path in the R/start_ncs.vim and R/before_ncsv.vim the windows file path but I wasn't successful.

jalvesaq commented 1 year ago

Yes, you understand my hypothesis perfectly. It's just a guess and I can't help more because I don't have a Windows machine. Anyway, the method to test the hypothesis is what you are trying: hard code the value of nvim_r_home at either R/start_ncs.vim or R/before_ncs.R.

alejandrohagan commented 1 year ago

hi! Yes that fixed that issue, unfortuately another issue popped up and that is because I believe you are using the system command make to build the package however in my git bash I don't have the make function.

Instead my comptuter uses a different instance of mysys which is Rtools to make commands.

ERROR: R exit code = 1! Please, run :RDebugInfo for details. RInitOut

.build_packages() exit status 0

jalvesaq commented 1 year ago

The command to build the nvimcom library is in R/before_ncs.R:

tools:::.build_packages(paste0(nvim_r_home, "/R/nvimcom"), no.q = TRUE)

You could try to install make and gcc in MSYS2 because R requires them to install packages which have C code.

alejandrohagan commented 1 year ago

Thanks -- let me play around with the different options -- I'm limited in what I can install on my computer here. If you don't disagree -- we can close issue as I think its a limitation on my end at this point and not the package.

Thanks for the all the responsiveness -- I really appreciated it!

jalvesaq commented 1 year ago

Please, see https://github.com/jalvesaq/Nvim-R/wiki/Remote-access You don't need to set the environment variables, but perhaps setting some of R_app, R_cmd, R_compldir, R_tmpdir, R_remote_tmpdir, and R_nvimcom_home will solve your problem.