How to get package and function together with code completion in RStudio?

Viewed 266

This would be handy for conflicting functions, and more generally to systematically include the package for debugging purpose or communicating the code to others. Having to write down the package manually is time consuming and could be avoided with code completion.

this question has 2 parts:

1) How to include masked functions in the completion pop-up menu ?

Example:

x magrittr::set_names() masks purrr::set_names()

while typing set_n and tab in the text editor, we only see the unmasked function magrittr::set_names() in the completion menu. I'd like to be able to pick the one I need from the menu.

2) How to get code completion to write down both package::function() ?

Example:

for magrittr::set_names() when tabbing twice set_n in the text editor, code completion only writes down the function set_names(). I'd like to get completion to write down the full designation magrittr::set_names().

1 Answers

I agree with the other comments - what you directly ask for is a feature request for RStudio. The tab completion for function names only works for attached functions. If you attach packages, then the masking rules will apply.

However, a good solution (and the one I use) is not ever to attach packages, and call them explicitly with the full name. Here, the RStudio tab completion can also help out a lot.

Example: type mag and hit tab. You'll get 'magrittr::' among the suggestions. Then type set and 'magrittr::set_names' is among the top suggestions.

A little bit more typing, but it solves your problem and gives you full control over the package::function combinations you need.

Related