In Rstudio, Ctrl - Shift - M
inserts the %>%
pipe command. Here I’ve just listed how to get similar functionality across a range of editors. The following scripts show how to implement the R pipe in Emacs and the Vscode.
R Pipe in Visual Studio Code
{
"key": "ctrl-shift-m",
"command": "editor.action.insertSnippet",
"args": {
"snippet": "%>%"
},
"when": "editorLangId == 'r'"
}
R Pipe in Emacs
;; Taken from
;; https://emacs.stackexchange.com/questions/8041/how-to-implement-the-piping-operator-in-ess-mode
(defun then_R_operator ()
"R - %>% operator or 'then' pipe operator"
(interactive)
(just-one-space 1)
(insert "%>%")
(reindent-then-newline-and-indent))
(eval-after-load "ess-mode"
(define-key ess-mode-map (kbd "C-%") 'then_R_operator)
(define-key inferior-ess-mode-map (kbd "C-%") 'then_R_operator))