Replace df <- df %>% ... with a shortcut

Viewed 83

I guess most of us have already used something like this (at least if you are using the tidyverse):

library(tidyverse)

example <- mtcars
example <- example %>%
  select(- mpg)

My question: I know there is a shortcut for this part:

example <- example %>% ...

But I can neither remember nor find it on Google.

I think it was something similar to this %<>%.

Can anyone help?

Please excuse me if this question was already asked before.

Best regards

2 Answers

This lhs %<>% rhs from the magrittr package. So in your case example %<>% select(- mpg)

You can also use {dotdot} :

library(dotdot) 
example := .. %>%...

It works with everything, not just magrittr. The .. after := are replaced by the variable.

Related