Deletion in renv projects
I'm unable to edit any file through Nvim-R when using the renv version control system, because whatever I type is immediately deleted. I've seen #445 and followed the strategies there, and Nvim seems to be able to start up fine and can even start a console session with <Leader>rf. Running :RDebugInfo also doesn't give me any error logs, only saying that I have nvimcom 0.9-123 and R 4.1.2.
I'm pretty sure it's a problem arising out of renv and Nvim-r used together, because my renv projects work fine when editing in RStudio and VSCode, and Nvim-R works fine when I am editing a non-renv project. Any advice on this would be greatly appreciated!
Using R 4.1.2, nvimcom 0.9-123. Running on Linux (arch); error experienced on both Konsole and Xterm.
I'm sorry for not replying before, but I don't use renv.
As I read about renv, it restores old libraries. That's not going to work with Nvim-R/nvimcom because I change nvimcom's version number when there is any change that makes them incompatible. So, if you are going to use a previous version of nvimcom you also have to use its contemporary version of Nvim-R.
Anyway, I have no idea of what might be causing code to be deleted because there is no command from nvimcom to Vim/Neovim that deletes code. The commands from R to Vim/Neovim are for opening documentation, highlighting functions, finishing omni-completion, etc...
Is there any option in renv to exclude specific libraries from its management system?
renv has an option for using an external library, see renv.settings.external.libraries. I temporarily put this snippet before source("renv/activate.R") to copy the nvimcom from the default location to the file.path(Sys.getenv("TMP"), "NVIMR") and specify it as the external library. This may not be very robust, but works for my case.
if (
# running in vim
!is.na(Sys.getenv("VIM", unset = NA)) &&
# get the original lib paths where nvimcom is installed
!is.na(ori_libs <- Sys.getenv("R_LIBS_USER", unset = NA)) &&
# test if nvimcom is there
dir.exists(nvimcom <- file.path(ori_libs, "nvimcom"))
) {
tmp_libs <- file.path(Sys.getenv("TMP", unset = tempdir()), "NVIMR")
if (!dir.exists(tmp_libs)) dir.create(tmp_libs)
file.copy(nvimcom, tmp_libs, recursive = TRUE)
options(renv.settings.external.libraries = tmp_libs)
}
source("renv/activate.R")
One thing I notice is that it takes much more time to get renv loaded when nvimcom is added, compared to in RStudio. Did not know the reason though.