jalvesaq / Nvim-R

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

nvimcom tries to rebuild/update every time and R exits leaving locked repo dir #756

Closed ImNotaGit closed 1 year ago

ImNotaGit commented 1 year ago

I have set up the latest Nvim-R (currently d8f7588) with Neovim v0.9.2 and R 4.2.1.

The issue I have is that each and every time I start Nvim-R, for some reason Nvim-R would try to rebuild and re-install nvimcom, but then there is the message "ERROR: R exit code = 1!". :RDebugInfo gives the messages below, apparently nvimcom has built and installed successfully, and there is only a cryptic error in the last line. However, this still leaves a locked 00LOCK-nvimcom repo dir in my libPath.

I have to manually remove the locked dir before restart Neovim and Nvim-R (if I don't to this, I'll get an error message "Error opening '/R/x86_64-pc-linux-gnu-library/4.2/00LOCK-nvimcom/DESCRIPTION'" when I restart Nvim-R). This second time, Nvim-R would only try to update nvimcom and build the completion list, then R can start successfully and everything would work, but only for this time. If I then quit Neovim and restart, the same issue as described above repeats itself (i.e. fails every first time, works only every second time, etc.)

RDebugInfo:

RInitOut
* checking for file ‘<my_home_dir>/.local/share/nvim/site/autoload/Nvim-R/R/nvimcom/DESCRIPTION’ ...
 OK
* preparing ‘nvimcom’:
*
 checking DESCRIPTION meta-information ...
 OK
* cleaning src

* checking for LF line-endings in source and make files and shell scripts
* checking for empty or unneeded directories
* building ‘nvimcom_0.9-147.tar.gz’
... (omitting build info)
Why build nvimcom
nvimcom version mismatch
RInitErr
Warning: invalid uid value replaced by that for user 'nobody'
Warning: invalid gid value replaced by that for user 'nobody'

.build_packages() exit status 0
* installing to library ‘<my_libPath_prefix>/R/x86_64-pc-linux-gnu-library/4.2’
* installing *source* package ‘nvimcom’ ...
** using staged installation
** libs
installing via 'install.libs.R' to <my_libPath_prefix>/R/x86_64-pc-linux-gnu-library/4.2/00LOCK-nvimcom/00new/nvimcom
** R
** byte-compile and prepare package for lazy loading
** help
*** installing help indices
** building package indices
** testing if installed package can be loaded from temporary location
** checking absolute paths in shared objects and dynamic libraries
** testing if installed package can be loaded from final location
** testing if installed package keeps a record of temporary installation path
* DONE (nvimcom)
Error in if (pkg == "base") file.path(.Library, "base") else if (isNamespaceLoaded(pkg)) getNamespaceInfo(pkg,  :    the condition has length > 1 Execution halted

First I cannot figure out why nvimcom installation failed the first time with the locked repo. Apparently every second time nvimcom would successfully install/update. Besides I'm not sure why nvimcom tries to reinstall itself each and every time... Honestly I would rather have an option to disable the auto update entirely, and if OK I'm ready to modify the source code to change this behavior for my install.

Any help on this is much appreciated.

jalvesaq commented 1 year ago

The message "nvimcom version mismatch" means that nvimcom's version in the Nvim-R directory (0.9-147) is different from the nvimcom version already installed. It seems that you have installed a previous version of nvimcom as a different user ("nobody"). Now, you don't have permission to update it in the same directory.

The versions must match because some function calls, the format of the output, or something else changes from one version to another. If the versions are different, either Nvim-R will call a nvimcom function wrongly or nvimcom will output something that Nvim-R can't interpret.

jalvesaq commented 1 year ago

Could you update Nvim-R, please? The script R/before_ncs.R now checks if nvimcom was installed by the current user. This might help users to debug similar issues.

ImNotaGit commented 1 year ago

Hi Jakson, wow, thanks for the super fast response.

It turned out that I have an old Nvim-R cloned repo under ~/.vim/bundle, and somehow Neovim and Nvim-R picked that up and tried to install the corresponding old nvimcom version (I have switched from Vim to Neovim some while ago). After removing the old Nvim-R repo and cleaning up any old nvimcom install in my R libPath, I updated Nvim-R via vim-plug and tried again.

However, now Nvim-R cannot complete the startup. I can see the R command line window showing up but not reaching the > prompt of R, and something like "term://~//28227:R " displaying in the bottom. Whenever I tried to send any R code, the message says "Not ready yet", and it got stuck there.

Edited: OK, so I realized that I could go to the R command line window and press i to enter insert mode, then I could see the > prompt and interact with R (although still cannot send any code from the "editor" window), and I also see the message "nvimcom: Environment variable NVIMR_SECRET is missing." In my neovim config file, I have this line below to start R automatically when editing an R file, and I'm suspecting that this is causing the issue:

autocmd FileType r if string(g:SendCmdToR) == "function('SendCmdToR_fake')" | call StartR("R") | endif

Any suggestions as to how to resolve this? Thanks again.

jalvesaq commented 1 year ago

I can replicate the same result. The problem is that the nclientserver is started and the required environment variables to start R are set asynchronously. When you start R during the FileType event, the variables were not created yet.

I will see if it is simple to implement an auto-start option...

jalvesaq commented 1 year ago

Actually, the option already exists: R_auto_start.

ImNotaGit commented 1 year ago

R_auto_start works! Sorry I missed that obvious option...

Thanks for your help and this wonderful plugin -- I've been heavily depending on it for the past 7 or 8 years of my life! That said many of my Nvim-R settings are inherited from quite old versions (like the autocmd above) and I never touched them unless something broke. I probably should reread the documentation and update my settings...

jalvesaq commented 1 year ago

Thanks for the feedback!