jalvesaq / Nvim-R

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

`R_app`, `R_cmd` options are not respected in LunarVim #793

Closed mschubert closed 10 months ago

mschubert commented 10 months ago

I've tried multiple ways of setting the options R_app, R_cmd in LunarVim's ~/.config/lvim/config.lua. However, every time I start with <Leader>rf, it starts R instead of radian:

-- this sets the option (i.e., assign works if set here)
vim.g.R_assign = 0
vim.g.R_app = "radian"
vim.g.R_cmd = "R"

lvim.plugins = {
    {
        "jalvesaq/Nvim-R",
        lazy = false,
-- Error detected while processing /home/mschu/.local/share/lunarvim/lvim/init.lua:
-- Lua module not found for config of Nvim-R. Please use a `config()` function instead
--        opts = {
--            { "R_app", "radian" }
--        },
        config = function() -- alternatively, this also sets the option (i.e., assign works if set here)
            vim.g.R_app = "radian"
            vim.g.R_cmd = "R"
        end,
        keys = {
            { "<C-Space>", "<Plug>RDSendLine", desc="Send current line to R" }
        }
    }
}

-- this does not set the option (i.e., assign does not work if set here)
lvim.lang = {
    r = {
        R_assign = 0,
        R_app = "radian",
        R_cmd = "R"
    }
}

R_assign = 0 is respected and the <C-Space> mapping works as well. I've tried each way of setting the R_app and R_cmd options separately, which also does not work.

If I remove R_cmd = "R", I do get the startup error

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

where :RDebugInfo states

Usage: radian radian: error: no such option: --slave

so the option does seem to get set, expect that R gets started instead of radian as soon as I set R_cmd.

I don't know if I'm approaching this the wrong way or what else might be happening.

jalvesaq commented 10 months ago

Nvim-R is an old plugin configured by global variables that must be set before its code is sourced. So, what happens if you try this before lvim.plugins{}:

vim.g.R_assign = 0
vim.g.R_app = "radian"
vim.g.R_cmd = "R"
mschubert commented 10 months ago

Thanks for the quick answer!

I already tried this (see lines 1-3 above) and it doesn't solve the issue, unfortunately.

jalvesaq commented 10 months ago

I installed LunarVim and couldn't replicate the bug. I don't have radian installed, but I created a symbolic link to R named "radian"; I also tried a symbolic to bash named "radian". In both cases, :RDebugInfo shows the expected output before starting R (R_before_nrs is R_cmd). Of course, nothing works after starting bash instead of R, but it's clear that the values of R_app and R_cmd defined in the config.lua are respected. The config you posted when opening the issue works, but, because you repeat the same configuration three times, of course, at least one of them works and the other two either work or are harmless. More precisely, the first two work and the third one (lvim.lang) does nothing.

mschubert commented 10 months ago

I'm getting the following :RDebugInfo, I guess there is some kind of error (RInitErr)?

RInitOut
nvimcom_info
  version: 0.9-161
  home: /home/mschu/R/x86_64-pc-linux-gnu-library/4.3/nvimcom
  Rversion: 4.3.2
RInitErr
Time
  R_before_nrs: 0.160372
  start_nrs: 0.001711
  common_global: 6.84731e-4
jalvesaq commented 10 months ago

There is no error. RInitErr is the stderr output of R_before_nrs. It's empty because there was no output to stderr. And even if there was output, it could be only informational. I will change the names of the fields of :RDebugInfo...

mschubert commented 10 months ago

Oh no - I just realize, I made a mistake here: The command indeed already started radian, but I mistook it for R because I didn't set g:R_hl_term = 0.

So everything works, sorry for the nuisance!

jalvesaq commented 10 months ago

No problem. This was an opportunity to improve :RDebugInfo...