This article outlines the code completion features in the RStudio IDE.
SMARTER COMPLETION ENGINE
Previously, the RStudio IDE only completed variables that already existed in the global environment, now completion is done based on source code analysis so is provided even for objects that haven’t been fully evaluated:
Completions are also provided for a wide variety of specialized contexts including dimension names in [ and [[:
The RStudio IDE now provides completions for function arguments within function chains using magrittr’s %>% operator, for e.g. dplyr data transformation pipelines. Extending this behavior, we also provide the appropriate completions for the various ‘verbs’ used by dplyr:
In addition, certain functions, such as library() and require(), expect package names for completions. RStudio automatically infers whether a particular function expects a package name and provides those names as completion results:
Completion is now also S3 and S4 aware. If RStudio is able to determine which method a particular function call will be dispatched to it will attempt to retrieve completions from that method. For example, the sort.default() method provides an extra argument, na.last, not available in the sort() generic. RStudio will provide completions for that argument if S3 dispatch would choose sort.default()
Beyond what’s described above there are lots more new places where completions are provided:
- For Shiny applications, completions for ui.R + server.R pairs
- Completions for knitr options, e.g. in opts_chunk$get(), are now supplied
- Completions for dynamic symbols within .C, .Call, .Fortran, .External
ADDITIONAL ENHANCEMENTS
Always On Completion
Previously RStudio only displayed completions “on-demand” in response to the tab key. Now, RStudio will proactively display completions after a $ or :: as well as after a period of typing inactivity. All of this behavior is configurable via the new completion options panel:
File Completions
When within an RStudio project, completions will be applied recursively to all file names matching the current token. The enclosing parent directory is printed on the right:
Fuzzy Narrowing
RStudio now uses ‘fuzzy narrowing’ on the completion list, by checking to see if the completion matches a ‘subsequence’ within each completion. By subsequence, we mean a sequence of characters not necessarily connected within the completion, so that for example, ‘fpse’ could match ‘file_path_sans_extension’. This is helpful when completing long variable names, or variable names that are difficult to remember.
Symbol Legend
The following symbols are used to disambiguate the various completions:
Good stuff. Could you please explain the meanings of the different icons? For example, data frames get listed twice the pop-up: once prefixed with the yellow rectangle and once with a box that looks like a worksheet. I presume it doesn't matter which a user chooses - but it could confuse beginners.
I second Leon's question. What is the meaning of the different icons used in code-completion?
I third the question. It is strange (and annoying) to see every option duplicated.
Hi everyone,
I've added a simple symbol legend that should help explain what the various icons represent; in addition, the duplication of autocompletion symbols should be addressed in the next RStudio release.
Thanks!
Kevin
Is it a bug, or am I missing something obvious - my RStudio standalone installation (0.99.486) has stopped giving me auto-complete for data.frame names after the $.
It used to work fine, but now reports: (No matches)
Auto-complete still works on my RStudio Server instance (same 0.99.486).
Also, take the (sexist?) default "women" data frame, for example.
I don't think partial DF names should execute, eg:
One thing that has confused me since this change to autocomplete is function arguments. Is there a way to turn back on the ability to see all of the arguments for a function? For instance, if I am using the format() function and I tab to autocomplete, all I see is the "x" and "..." parameters. However, if I add an "x", like format(x = foo,) and tab after the "," I get 14 more possible parameters. There are also other cases where I get no arguments, usually when there are many variable names in the autocomplete. I really like the RStudio autocomplete, but have been having trouble with it since this change a couple years back. For one, it used to be very easy to see all the variable names and then select one without having to F1 into the documentation. Thanks!