Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IntelliSense should suggest dataframe variables after dplyr pipe (%>%) #527

Closed
danielbasso opened this issue Jan 18, 2021 · 3 comments
Closed

Comments

@danielbasso
Copy link
Contributor

In my quest to replace Rstudio, I found this extension. After some troubled start (even opened a "bug request that was totally my fault), I'm linking it a lot. I can preview dataframes, have a session explorer and even show plots and help in separated tabs.

There is only one feature that I'm missing a lot and makes a huge difference in my workflow. dplyr has become a standard for data munging with R. It's clean, is part of tidyverse, has a standardized syntax, etc, etc. When using Rstudio, whenever you start with a dataframe and then use the pipe (%>%) operator, all the dataframes variables became available as suggestions for autocompletion:

image

Even works after the first pipe:

image

This is a huge time saver for me, because I normally work with dataframes that have 100+ variables whose variable names consists of abbreviations of words, theoretical example "loa_tot_prc" (loan total price).

Unfortunately, the same doesn't happen with the current state of Vscode, at least from what I searched:

image

(here I created the my_df object outside the script file otherwise IntelliSense will suggest variable names just because it found them earlier in the code).

My workaround now is to call an names(my_df) and then manually search the variable names that exists.

Because the logic behind this is "kinda" straightforward:

  1. Check for pipe operator;
  2. Call names() for the dataframe prior to the pipe;
  3. Use the result of the names() call as suggestions.

I could try and implement it by myself, but I have -10 experience developing extensions to Vscode, or with Vscode in general. I was reading about how this could be done (https://code.visualstudio.com/api/language-extensions/programmatic-language-features) and it seems doable, at least in theory.

What do you guys think? It's hard, not so much? Maybe if pointed to the right direction I could try by myself. I need help/instructions in this regard.

@psobolewskiPhD
Copy link

Hmm, for me this works already?
image
To be fair, var1, var2, var3 were at the bottom of the list, so I had to hit up-arrow.

Interestingly, when I repeated your example exactly, in other words having the df defined in the terminal and not the script window, it does't work anymore...

@danielbasso
Copy link
Contributor Author

danielbasso commented Jan 19, 2021

Hi @psobolewskiPhD,

thank you for your reply.

IntelliSense sometimes suggest variable names simply because they are present elsewhere in the script file. If you load a dataset from a file or from a database, it won't work that way. Check my previous post:

(here I created the my_df object outside the script file otherwise IntelliSense will suggest variable names just because it found them earlier in the code).

I'm willing to give this implementation a try, but I would need some help, specially in the beginning.

@renkun-ken
Copy link
Member

Duplicate of #323.

Closing this in favor of the existing one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants