Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FR] Create a config to turn on autoreplacement of magrittr pipe with native pipe #57

Open
jarodmeng opened this issue Feb 26, 2024 · 5 comments
Labels
enhancement New feature or request

Comments

@jarodmeng
Copy link

This is a feature request.

I'm in the process of migrating all my pipe usage from the magrittr %>% pipe to the R native |> pipe. But old habits truly die hard and I find my self mixing the two pipes all the time in my script. As a result, I have to do global replacement often. I'm wondering if it's possible to enable some kind of auto-replacement of %>% to |> in real time when typing. There can be a setting which turns on and off this behavior.

Congrats on the new launch and thanks for all the hard work over many years!

@PMassicotte
Copy link
Collaborator

I am not sure to understand. Do you mean that |> would be inserted even if you type %>%?

@jarodmeng
Copy link
Author

I am not sure to understand. Do you mean that |> would be inserted even if you type %>%?

That's right. Much like when _ is typed, it's replaced with <- if R_assign is turned on.

@jalvesaq
Copy link
Member

You may put this in your init.lua:

vim.cmd.iabbrev('%>', '|>')

or, even better, to unlearn the old habit:

vim.cmd.iabbrev('%>', 'TRY_AGAIN')

You can also create an autocmd to automatically replace "%<%" with "<|" when the buffer is saved.

@jarodmeng
Copy link
Author

I tried to set up the abbreviation, but it doesn't work. It may have something to do with the characters allowed in abbreviation.

I ended up doing this in 2 steps.

  1. I used grep --include={*.R,*.r,*.qmd,*.rmd} -rli '%>%' * | xargs -i@ sed -i 's/%>%/|>/g' @ to replace all existing %>% with |> in my folder.
  2. I included autocmd BufWritePre *.R,*.r,*.qmd,*.rmd,*.Qmd,*.Rmd :%s/%>%/|>/ge | write in my setup to automatically replace %>% with |> in R files when saving.

It doesn't solve the real-time replacement when typing, but at least help make sure that my R files now always have |> instead of %>%.

@jalvesaq jalvesaq added the enhancement New feature or request label Apr 27, 2024
@PMassicotte
Copy link
Collaborator

I think it was addressed in #116

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants