RStudio autocompletion in tidyverse and formula syntaxes

I'm really interested in how different R syntaxes function for learners pedagogically (see my syntax comparison cheatsheet, and associated FAQ). Personally, I'm moving away from the formula syntax in my teaching and toward the tidyverse syntax. I've been anti-base-R-for-teaching for a long while. However, I recently realized not using base syntax has a major disadvantage-- no autocompletion!

If I type mean(mtcars$ and hit tab, I get a little dropdown of all the variables in my dataset. Not so with

mtcars %>%
filter(

and hit tab. I understand why typing

lm(

and hitting tab doesn't give me anything, because it would have to search the entire environment/namespace for possibilities. I'm not a software developer, but it seems like the first example would be doable, because piping the data into the filter() command limits the environment to just that dataset. Are there any plans to improve autocompletion for other types of syntax?

3 Likes

I actually do get a dropdown with column names when I do mtcars %>% filter( and then tab. In case this is version dependent, I'm using RStudio 1.1.442.

Hmm, I just updated to the preview version of RStudio and the newest version of dplyr and am seeing the same behavior as ever. There is a dropdown in filter, but it's not suggesting variable names, which is what I'm interested in. autocompletion

1 Like

It looks like in the console RStudio doesn't include column names in the dropdown if you press enter after the pipe, so that the filter( statement is on a new line. I get the same behavior as you when I put filter( on a new line.

In a script:
19%20AM

In the console, single line:
40%20AM

In the console, multiple lines:
25%20AM