jalvesaq / cmp-nvim-r

GNU General Public License v3.0
18 stars 1 forks source link

Inconsistent completions for piped data.frame #5

Closed liamvdvyver closed 1 year ago

liamvdvyver commented 1 year ago

Hello,

Completions for column names of a data frame piped into a function seem to work incosistently. Below are a few examples:

library(tidyverse)
data(iris)

df1 <- iris %>% select(Species)

df2 <- iris %>%
    select(Species) %>%
    filter(Species == "setosa")

df3 <- iris %>%
    group_by(Species)

When assigning df1, no column names are suggested. When assigning df2, colums are suggested in select(), but not in filter(), although filter() works fine when it is the first function after the pipe on a new line. When assigning df3, no columns are suggested in the group_by().

Thanks!

jalvesaq commented 1 year ago

Thanks for reporting the issues. I will soon try to fix the df1. The case of df2 can't be fixed with the current implementation because cmp-nvim-r would have to know that select() returns a data.frame.

Adding the line below to your init.vim should fix the issue with df3:

let R_fun_data_1 = ['select', 'rename', 'mutate', 'filter', 'group_by']

If using init.lua:

vim.g.R_fun_data_1 = {'select', 'rename', 'mutate', 'filter', 'group_by'}
liamvdvyver commented 1 year ago

As for df2, in my experience normally longer pipelines are just manipulating data frames till the final step, so it would be useful to have completions coming from the first item in the multi line pipeline. I plan on implementing this for myself, if you share my view I'll send a PR when I finish. It may be best to add a setting and make it non default to prevent innaccurate suggestions.

jalvesaq commented 1 year ago

Yes, I agree. Please, do it.