6

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

markus
  • 25,843
  • 5
  • 39
  • 58
KevR
  • 131
  • 7
  • `%<>%` is exactly what you're looking for. Look at the [magrittr docs](https://cran.r-project.org/web/packages/magrittr/vignettes/magrittr.html) for a reference – Lukas Thaler Jun 05 '20 at 06:54
  • Off topic, but for this particular example, a cleaner solution would be base R: `example$mpg <- NULL` – s_baldur Jun 05 '20 at 10:32

2 Answers2

5

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

Ahorn
  • 3,686
  • 1
  • 10
  • 17
0

You can also use {dotdot} :

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

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

moodymudskipper
  • 46,417
  • 11
  • 121
  • 167