Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 271
alp Avatar asked May 26 '20 12:05

alp


People also ask

How do I get suggestions in R studio?

A suggestion list will pop up as you type or can be accessed manually by either pressing Tab or Ctrl + Space. You can adjust those settings in Global Options -> Code -> Completion. To fill in the suggested phrase you have to press either Tab or Enter, pressing Ctrl + Space with auto-completion list open will close it.

How do you enter codes in R studio?

In addition, if you have typed the character sequence for a snippet and want to insert it immediately (without going through the completion list) you can press Shift+Tab.

What does search function do in R?

search() function in R Language is used to get the list of all the attached packages in the R search path. Parameters: This function takes no parameters.


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.

like image 63
randr Avatar answered Oct 31 '22 18:10

randr