4

When using the R Extension for Visual Studio Code the code completion always suggests %in% for a line that ends with the magrittr pipe %>%. The final % in %>% triggers an autocomplete suggestion of %in%.

Here's what happens when writing a code block:

library(dplyr)
mtcars %>%
    select(mpg, cyl) %>%

enter image description here

Is there anyway to fix this? If I type "enter" for a newline like I normally would in any other text editor, visual studio code inserts the %in% at the end of the line, which clearly isn't what I want.

I'm not sure where I can tweak any configurations - whether in visual studio code, or the R extension, or the R language server.

MangoHands
  • 1,141
  • 9
  • 11
  • Do you type `%>%` by hand or a keyboard shortcut? I set a shortcut for `%>%` in vscode and never meet this issue. – Darren Tsai Jan 08 '23 at 16:26
  • I type `%>%` by hand. – MangoHands Jan 08 '23 at 17:21
  • You could add `"editor.suggestSelection": "recentlyUsed",` to your settings.json so that it recommends what you've used most recently? Options for this setting are _first_, _recentlyUsed_, and _recentlyUsedByPrefix_. – Kat Jan 08 '23 at 18:26

2 Answers2

0

Since the accepted answer isn't useful (whereas MangoHands comment is), I'm reposting his comment as a separate answer:

You can disable the acceptance of suggestions via the enter button which and instead use (only) tab to accept suggestions, which I find intuitive.

To this end add the following line into the Preferences: Open User Settings (JSON) option from visual studio (Use Ctrl+Shift+P/Cmd+Shift+P to open the command palette and search for Preferences: Open User Settings (JSON)):

"editor.acceptSuggestionOnEnter": false

PS: Using the shortcut for the pipe (Cmd+Shift+M) is cute until you realize that it won't work in the terminal - at least noy in radian- (instead you shift to the 'problems' tab), which for me is a huge and annoying issue.

PejoPhylo
  • 469
  • 2
  • 11
-1

Try this in your settings.json. It should prevent from suggestion of unnecessary strings comments and also %>% or %in%.

  "[r]": {
    "editor.quickSuggestions": {
      "other": false,
      "comments": false,
      "strings": false
    }
  }
MarBlo
  • 4,195
  • 1
  • 13
  • 27
  • 1
    Thanks for the tip! Your suggestion turned off suggestions altogether, but I could trigger suggestions with control + space. I decided to use `"editor.acceptSuggestionOnEnter": "off"` as a compromise. – MangoHands Jan 26 '23 at 02:25