dy_by
dy_by

Reputation: 1241

How to fast insert new 'pipe operator' in Rstudio?

I have been using the ctrl + shift + m shortcut to insert well known %>% pipe operator. Since the release of R version 4.1.0 and adding a new |> to base, I wonder is the corresponding shortcut available in Rstudio?

Upvotes: 53

Views: 26145

Answers (3)

Wencheng Lau-Medrano
Wencheng Lau-Medrano

Reputation: 752

I found a solution for having shortcuts for both native and magrittr pipes in RStudio (only): addings.

You can get a very detailed description of how addinexamples package works in https://rstudio.github.io/rstudioaddins/

Important: this solution is only valid in RStudio.

Instructions:

  1. Install the addinexamples package from the fork on my profile: https://github.com/LuisLauM/addinexamples by running:

devtools::install_github(repo = "https://github.com/LuisLauM/addinexamples")

  1. Go to Tools --> Modify keyboard shortcuts

enter image description here

  1. Find out the field Insert |> (tip: you can sort the list by clicking the headers of the shortcut table).

enter image description here

  1. Remapping the shortcut with the key combination that you want (tip: it seems that not all the combinations are allowed. For instance, I try with Ctrl + Shift + , but it didn't work, then Ctrl + Shift + Space did).

You can always fork, edit and compile the rstudioaddins package in order to have your own customized shortcuts. You can use my forked version as a guide to determine what files you had to modify. The package allows to create interactive addins, so it is very powerfull.

Upvotes: 4

Nate Hall
Nate Hall

Reputation: 84

one option that works okay is to add a snippet to your code snippets if you're an rstudio user. You'd then need to hit the snippet name and then tab complete it. The ${0} then drops your cursor one whitespace away from the pipe so you save a keystroke there:

snippet p
  |> ${0}

Upvotes: 1

Phil
Phil

Reputation: 8127

It's the same shortcut. If you install the latest version of the IDE, and go to the Global Options window, select "Code" and you'll see an option for "use native pipe operator, |>". Select that for the shortcut to take effect.

enter image description here

Upvotes: 75

Related Questions