2 followers Follow

automatically load packages like the auto import in IntelliJ IDEA

There is a similar request not answered in 2013:

The Java IDE IntelliJ IDEA have a feature called auto import, which would:

1. Automatically add import statements for all classes that are found in the pasted block of code and are not imported in the current class yet

2. Automatically display import pop-up dialog box when typing the name of a symbol that lacks import statement.

In R we use lots of packages, it's not a trivial task to add package loading statements from time to time, even if you load the common used packages in beginning, you probably will find yourself load more packages later.

The implementation I imagined will be like this:

When typing a function name or object name not found in current search list but can be found in installed packages, prompt to either

   1. give prefixed full name like package::function(), this can be used in console or one time usage.

   2. give suggestion like the function is already available, after user finish the current line, insert package loading and attaching statement

            a. before current line

            b. in the beginning of the .R file

            c. in the beginning of code chunk of .Rmd file

There are more details about what kind of statement to use (library or require, one package in a line or all packages in one line), and where to put the loading statement more specifically. An ideal solution would be provide the most common usage and some customizing template options.

I think this feature can be an important productivity boost to RStudio users.

If the searching names in all installed packages bring too much performance hit (I think it could be minimized with full index), this feature can be called by keyboard short-cut only instead of automatic pop up. So user still get regular prompt when he stopped or pressed tab, but will get fully searched help with another keyboard short-cut key.




Hi David,

Thanks for the feature request -- I've filed this for the development team, and we'll see what we can do!


Kevin Ushey 0 votes

I made a RStudio addin for this. Because the addin mechanism don't have access to the popup list, I have to use a Shiny gadget window to search names.

My package is here:

If RStudio decided to incorporate similar feature, feel free to check the source code or contact me.

david 0 votes