Maya9786
Maya9786

Reputation: 37

Rewrite code using the magrittr compound assignment pipe-operator %<>%

How would I rewrite the below code using %<>% ?

The new value of cemetaries will be the result of...

cemetaries <-

Start with cemetaries, AND THEN...

  cemetaries %>%

SELECT 3 COLUMNS, THEN EVERTHING ELSE, AND THEN...

 select(LEGAL, OWNER, PROJECT, everything())

Upvotes: 0

Views: 73

Answers (1)

Ronak Shah
Ronak Shah

Reputation: 389325

You could replace the pipe operator (%>%) with %<>%.

cemetaries %<>% select(LEGAL, OWNER, PROJECT, everything())

The benefit of using %<>% is that it by default updates the lhs object so that you don't have to do cemetaries <- .

When you use pipe operator to save the changed object back you need to do :

cemetaries <- cemetaries %>% select(LEGAL, OWNER, PROJECT, everything())

cemetaries <- part can be avoided if you use %<>%.

Upvotes: 3

Related Questions