Add keybinding for %<>% magrittr pipe operator

magrittr

#1

I know you can modify the keybindings in Rstudio going to "Tools > Modify Keyboard Shortcuts"
But i use %<>% pipe operator too much and need to assign it to a keybinding (similar to Ctrl + Shift + M)

A workaround is to create a snippet for such pipe (Tools > Global options > Code > Edit Snippets):

snippet p
	${1:object} %<>% ${0}

But I rather assing a keybinding if possible. is there any way of creating such shortcut?


#2

Yes.

I have a package that has some pre-made key-bidnings and allows the user to define their own. Please give it a try: https://github.com/WinVector/addinexamplesWV.


#3

Just to generalize from John's example (which is great, btw), add-ins allow you to create keybindings for whatever it is that add-in does (whether it be inserting a pipe, as in this case, running code, etc.).

Jozef Hajnala wrote a post the other day that included a nice little gif of how to add a shortcut for an add-in (again, John describes this exact same thing in addinexamplesWV, this is just gravy)!
https://jozefhajnala.gitlab.io/r/r103-keypress-viewer/


#4

Thanks a lot! I will try the addin approach