could not find function "%>%" - what am I doing wrong?

I've used usethis::use_pipe() to create a file utils-pipe.R that loads the magrittr pipe.

#' Pipe operator
#' See \code{magrittr::\link[magrittr:pipe]{\%>\%}} for details.
#' @name %>%
#' @rdname pipe
#' @keywords internal
#' @importFrom magrittr %>%
#' @export
#' @usage lhs \%>\% rhs
#' @param lhs A value or the magrittr placeholder.
#' @param rhs A function call using the magrittr semantics.
#' @return The result of calling `rhs(lhs)`.

I've also got magrittr in the Imports: section of the DESCRIPTION file.


When I am in my package project in RStudio, and I use devtools::load_all("."), and then try to run a line of code using %>%, I get the error:

could not find function "%>%"

If I then actually attach the package with library() and run the line of code, I still get the error.
My belief was that either load_all() or library($my_pkg)ought to load the pipe and avoid this error. I've also not had this problem in other packages I've developed.

I can get round it by doing library(dplyr) or whatever, but I'd like to correct my understanding and work out why the pipe is not already loaded. Any ideas please?

1 Like

You need to run devtools::document() to parse the added Rd annotations and generate the NAMESPACE entries.

After that it should work how you expect.


That's done it - thanks Jim.
I was using load_all() as a shortcut to avoid running a full check.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.