0

I am using the pipe operator (%>%) from magrittr (via dplyr) in a package I am developing.

I have run usethis::use_package("dplyr"), and this makes the necessary adjustments to import dplyr.

But when running a function that uses the pipe operator, I get the following error:

Cannot find the function "%>%"

Usually that's because you need to prefix the function by referencing the package it came from e.g., dplyr::filter. However, if I call the pipe-operator like: dplyr::%>% I get an unexpected token error.

So how do I use the pipe operator in my package?

AndrewGB
  • 16,126
  • 5
  • 18
  • 49
eartoolbox
  • 327
  • 2
  • 10
  • 1) Did you try `use_package("magrittr")` instead of `use_package("dplyr")`? 2) To call `%>%` with `::`, wrap it in backticks: `dplyr::\`%>%\`` – Vasily A Jul 04 '21 at 12:06
  • [R: use magrittr pipe operator in self written package](https://stackoverflow.com/questions/27947344/r-use-magrittr-pipe-operator-in-self-written-package) – Henrik Jul 04 '21 at 12:13
  • Yes, 1) gives the same error 2) also gives the same error. It is the "d" of dplr that is not expected i.e consider: var 2 <- var dplyr::`%>%` dplyr::filter(mode < 2) } – eartoolbox Jul 04 '21 at 12:15
  • 1
    Ah okay, thanks Henrik. So the answer is to run usethis::use_pipe() – eartoolbox Jul 04 '21 at 12:21
  • 2
    You can use the new r base pipe. – Mostafa90 Jul 04 '21 at 12:41

0 Answers0