5

Using the code provided here I can use the magrittr package pipe %>%. I want to switch to the new native R pipe |>, but if I just substitute the old pipe with the new one the code is not recognized as continued and therefore is not indented. What it the best way to implement the new operator in ESS? This is the code in my .emacs file:

(defun then_R_operator ()
  "R - |> operator or 'then' pipe operator"
  (interactive)
  (just-one-space 1)
  (insert "|>")
  (just-one-space 1)
  (indent)
  (reindent-then-newline-and-indent))
(define-key ess-mode-map (kbd "C-S-m") 'then_R_operator)
(define-key inferior-ess-mode-map (kbd "C-S-m") 'then_R_operator)

This is an example of what I get:

data |>
some_function()

This is the expected result:

data |>
   some_function()
5
  • What version of ESS are you using? The latest version on Melpa as of 2021 11 04 properly indents |> without customization
    – Tyler
    Commented Nov 4, 2021 at 20:15
  • I am not sure what version it is, I installed the latest available for Ubuntu 21.10. Actually it does indent properly, but when I map it to the key combination as suggested in the linked post it does not indent anymore...
    – Claudio
    Commented Nov 5, 2021 at 18:26
  • You can find the version with M-x ess-version
    – Tyler
    Commented Nov 5, 2021 at 18:44
  • This works as expected for me. Can you provide a detailed example of the contents of your file, the keys you are pressing, and the results you see when you do?
    – Tyler
    Commented Nov 5, 2021 at 18:55
  • The version is 18.10.2. I added the code, the results and the desired result in the updated question.
    – Claudio
    Commented Nov 5, 2021 at 22:25

1 Answer 1

2

I finally managed to get what I need, I will list all the steps so that someone may comment on why some of the problems have come up:

  1. I tried to install ess from within Emacs, but I did not succeed because Emacs freezes;

  2. I removed melpa-ess (sudo apt remove --purge melpa-ess) from my Ubuntu installation. After that, ess was no longer listed when I issued the list-packages command;

  3. I downloaded and installed ess from MELPA;

  4. I added this code to my .emacs file to create a keybind:

(require 'ess-site)
(use-package ess
  :bind (:map ess-r-mode-map
         ("C-S-m" . " |> ")
         :map inferior-ess-r-mode-map
         ("C-S-m" . " |> ")))

Hope this helps others who have the same problem.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.