Import '%>% from magrittr package


I’m building my first package. For now it only contains one function:

#' Cleans GA Data
#' Takes ga_data and cleans it
#' @param x a data frame from GA API
#' @inheritParams tidyr::separate
#' @importFrom magrittr `%>%`
#' @return New source and medium columns
#' @export

ga_clean_data <- function(data) {

  data <- data %>%
    separate(sourceMedium, into = c("source", "medium"), sep = "\\/")



But I’m getting the following error:

Error in data %>% separate(sourceMedium, into = c("source", "medium"),  : 
  no se pudo encontrar la función "%>%"

May you tell me why is this happening?


Hi @o_gonzales, is "importFrom magrittr %>%" in your NAMESPACE file too?


Hi Edgar, thank you for your answer.

I only have:

exportPattern("^[[:alpha:]]+") in NAMESPACE.

I was having the same issue with “separate” from Tidyr not been found, and solved it with:

@inheritParams tidyr::separate

So I thought I could solve the magrittr error in the same way, but apparently not. May you tell me exactly what to add on “NAMESPACE”?


Ok, I just let roxygen2 write the NAMESPACE for me, so I know it’s correct, this reference may be of help:


@edgararuiz I’m come across another issue.

Now, my NAMESPACE is generated with this:

# Generated by roxygen2: do not edit by hand


But when I do “check” on it, I get:

==> devtools::check()

Updating googleAnalyticsReports documentation
Loading googleAnalyticsReports
Warning: object ‘`%>%`’ is not exported by 'namespace:magrittr'

May you take a guess on that? Thank you.


Oh, that’s because we need to remove the single tick from the reference, try:

#' @importFrom magrittr %>%

I just tested that to confirm


Solved, thank you for your guidance :clap:


As described in this quoted response from @mara, if your question has been answered, please mark the reply that answered it as the solution. Thanks!