14

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().

alp
  • 642
  • 5
  • 13
  • 1
    I'd like to know the answer to this too. But you might have more luck on their [support forums](https://community.rstudio.com/c/rstudio-ide). – Ian Campbell May 26 '20 at 12:43
  • @IanCampbell done: https://community.rstudio.com/t/how-to-get-package-and-function-together-with-code-completion-in-rstudio/67526 – alp May 26 '20 at 16:39
  • @IanCampbell [feature request raised on github](https://github.com/rstudio/rstudio/issues/7009) – alp May 30 '20 at 09:39
  • Can you update this post if you hear back from the RStudio devs? – Dunois May 31 '20 at 13:44
  • 1
    @Dunois got an answer on the feature request, bit elusive but it's taken into account apparently – alp Jun 02 '20 at 21:08
  • @alp thanks for your update! The dev's reply sounds hopeful? Sounds like it isn't something they'll implement immediately. I guess we'll just have to continue watching that space. – Dunois Jun 03 '20 at 08:08

1 Answers1

1

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.

randr
  • 255
  • 1
  • 7
  • 1
    thanks, that's a pretty good workaround actually, but that requires more typing as you mentionned, and to know very well all packages and functions. It would be defintiely better to have an option to turn on/off a global feature in the Completion panel, or add a shortcut to get it from the completion pop-up menu. I did raise a feature request on gitub, you can check the reply with link above in comments. – alp Jun 04 '20 at 19:45
  • 1
    I think I would find suggestions from all packages I have ever installed rather overwhelming and annoying - but I can see how in some cases this would be helpful. Having an option, as you propose, to switch the global completion scope on/off is a great idea. Let's hope the RStudio devs agree! – randr Jun 05 '20 at 14:48