Nvim-R
Nvim-R copied to clipboard
\o (evaluate and insert output as comment) fails if line contains a semicolon
\o works fine for me except when the line I want to evaluate has a semicolon in it, which I am assuming fails to get escaped somehow - I haven't taken a look at the code. The error I get is "Error: VECTOR_ELT() can only be applied to a 'list', not a 'NULL'".
This occurs for me even with a very minimal vimrc with just nvim-r.
set rtp^=$HOME/.dotfiles/nvim
call plug#begin('$HOME/.dotfiles/nvim/plugged')
Plug 'jalvesaq/nvim-r'
call plug#end()
Let me know if you can reproduce.
Nvim-R's documentation says:
The command
<LocalLeader>o
runs in the background the R commandprint(line)
, whereline
is the line under cursor, and adds the output as commented lines to the source code.
And, if you try
print(x <- 1)
print(x <- 1 ; y <- 2)
you will see that the second print command does not work. So, although the error message output in the RConsole after <LocalLeader>o
is different from what you get running the commands above, it is consistent with the documentation.
Anyway, I wil add a warning when there is a semicolon in the line...
OK, so this will fail in any case where a line is valid R code but has some characters print doesn't like, such as if there is a comment at the end. Would it be worthwhile for me to look into sanitizing input when I have some time, or is that outside the scope of nvim-r? If so, are there any other relevant parts of nvim-r besides the SendLineToRAndInsertOutput() function, and would there be anything else that is valid R "code" but breaks print besides ';' and '#'?
It seems to me that any inline comments could simply be removed before the line is sent, and foo(); bar()
could turn into
{
foo()
bar()
}
before being sent.
would there be anything else that is valid R "code" but breaks print besides ';' and '#'?
I don't know. Someone requested this functionality (\o
), and I implemented it, but I have never used it.
Nvim-R should sanitize the line. I will remove the #
and eveything to the right of it, and, please, post here any other cleaning that you think is necessary.
The code evaluated by nvimcom
is prefixed with the byte \x08
. So, to find all parts of Nvim-R that might generate invalid R code, you should search for SendToNvimcom("\x08"
.