Nvim-R icon indicating copy to clipboard operation
Nvim-R copied to clipboard

\o (evaluate and insert output as comment) fails if line contains a semicolon

Open dryya opened this issue 6 years ago • 3 comments

\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()

2018-04-19-182223_swaygrab

Let me know if you can reproduce.

dryya avatar Apr 19 '18 23:04 dryya

Nvim-R's documentation says:

The command <LocalLeader>o runs in the background the R command print(line), where line 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...

jalvesaq avatar Apr 20 '18 02:04 jalvesaq

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.

dryya avatar Apr 20 '18 05:04 dryya

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".

jalvesaq avatar Apr 20 '18 13:04 jalvesaq