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:









