jalvesaq / Nvim-R

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

Issue with omni completion for `data.table` #767

Closed iago-pssjd closed 9 months ago

iago-pssjd commented 1 year ago

Hi!

I am testing omni completion, so I added next lines to my ~/.vimrc file:

filetype plugin on
set omnifunc=syntaxcomplete#Complete
let R_set_omnifunc = []
let R_fun_data_2 = {'ggplot': ['aes'], 'with': ['lm', 'glm', 'lmer'], '[.data.table': ['.', 'list']}

Mainly, the goal is in last line. If DT is a data.table, then the next is possible:

library(data.table)
DT = data.table(x=rep(c("b"), 3), y=c(1,3,6))
> DT[, .(x)]
        x
   <char>
1:      b
2:      b
3:      b
> DT[, list(y)]
        y
   <char>
1:      1
2:      3
3:      6

so, I would want that when I have typed DT[, . or DT[, list(, omni-completion (through Ctrl-X Ctrl-O) would expand the list of variables (in this case x, y). Since DT[, .(x)] is equivalent to `[.data.table`(DT,, .(x)), or even to '[.data.table'(DT,, .(x)), I tried including this function in R_fun_data_2 as explicited above. However, it does not work; omni-completion expands the default menu instead of data.table variable names.

This happens both if I type DT[,., but also if I type `[.data.table`(DT,, .( or '[.data.table'(DT,, .(. I understand that working the first would be a FR for NVim-R (may I ask for it?). But the second and third should work already. Isn't it?

Thank you!

jalvesaq commented 1 year ago

The omni completion is not prepared to complete the names of columns within square brackets. If this feature were implemented, it should be for data.frames first because data.frame() is a function from the base library. However, I'm sorry, but I may not prioritize this soon because people not used to R notation have less difficulty understanding the use of filter() and select() from the dplyr library, which I'm using when writing new code. Of course, it would be great if someone could write a pull request for this.

iago-pssjd commented 1 year ago

Thanks for the answer.

Just a question more. I do not know vim insights to make a PR and do not understand the plugin code, but may I ask if the issue does occur through these lines and why within square brackets, even when explicited as part of a function name like in '[.data.table'(DT,, .(? https://github.com/jalvesaq/Nvim-R/blob/807871d93a03ef1029971ba558272a6a9e2326eb/R/complete.vim#L417-L436

jalvesaq commented 9 months ago

Closing because Nvim-R will not get new features.