Tidyverse does not include aliases from magrittr package?

Hi all,

I've recently started using tidyverse, instead of loading all the separate packages that I need regularly (e.g. dplyr, tidyr, magrittr). I'm a big fan of magrittr's piping operators and use them a lot. Additionally, I regularly use some of the aliases the package provides, like 'divide_by' instead of '/'.

However, it seems to me that these aliases have not been included in tidyverse, whereas the piping operators are. As a result, some of my code involving these aliases does not work when I only load tidyverse, so I have to load magrittr additionally. I've included reprex examples of both situations.

Example 1: loading magrittr - alias work:


test <- 5 %>%

#> [1] 0.5

Example 2: loading tidyverse - use of alias renders an error:


test <- 5 %>%
#> Error in function_list[k]: could not find function "divide_by"

#> Error in eval(expr, envir, enclos): object 'test' not found

Could you confirm that magrittr's aliases have been left out of tidyverse? Thanks!

1 Like

I've just poked at the tidyverse and magrittr packages on github. divide_by and friends are not available when you just load tidyverse because tidyverse doesn't expport them.

and it looks like, to me anyhow, that it might be an oversight that divide_by isn't available when you load tidyverse rather than loading magrittr.

Or maybe there was conscious decision to not make divide_by and friends available just to keep things more consistent with only one way to divide... I don't know

Here is what see happening.

magrittr exports divide_by and friends

tidyverse imports magrittr but what magrttr does to make divide_by is:

divide_by <- `\`

but magrittr never exports divide_by

What that means is that if you load magrittr yourself, rather than let tidyverse load magrittr for you, you will be able to use divide_by

When you only load tidyverse because tidyverse itself never exports divide_by (and friends) divide_by will only be available inside of the tidyverse package code (which isn't all that useful).

1 Like

Magrittr falls outside of the "core" packages loaded with library(tidyverse):

Tidyverse packages
The tidyverse also includes many other packages with more specialised usage. They are not loaded automatically with library(tidyverse), so you’ll need to load each one with its own call to library().

You see %>% thanks to the other packages importing that function in isolation. For example, if you load dplyr, you'll have it; search for magrittr in the NAMESPACE file to see.

(Oh, and apparently ditto for the tidyverse package itself.)


Ah, I get it now - magrittr et al. are installed when you install tidyverse, but you need to load it explicitly. I had that suspicion already, but was confused by the piping operator that did work without loading magrittr (just saw that this is not the case for the other 'rarer' operators (e.g. '%$%')).

Thanks for solving!

1 Like