Could not find function '%>%' when creating a package and running my @examples code.

Hey guys,
I'm creating a package for my function, however, when I build and 'check', it gives me an error
saying:

> checking examples ... ERROR
  Running examples in ‘TrumpWordFreq-Ex.R’ failed
  The error most likely occurred in:
  
  > base::assign(".ptime", proc.time(), pos = "CheckExEnv")
  > ### Name: Word_freq_trump
  > ### Title: Showing the change of Word Frequency Over Time
  > ### Aliases: Word_freq_trump
  > 
  > ### ** Examples
  > 
  > 
  > Word_freq_trump(Trump_DataSet, "america")
  Error in dataset %>% unnest_tokens(word, Speech, to_lower = T) %>% count(Date,  : 
    could not find function "%>%"
  Calls: Word_freq_trump
  Execution halted

I've imported dplyr and also tried importing magrittr where the pipe function comes from and scoped the function ''magrittr::%>%''. But that doesn't seem to work.

Any ideas what my error could be?

I think you need to add instructions to import these special functions. Add this line to the NAMESPACE file.

importFrom(magrittr,"%>%")
1 Like

If you're using the usethis package (which I highly recommend) just run usethis::use_pipe() and it should do all the necessary bits and pieces.

4 Likes

This worked perfectly, thank you soo much!

No worries, glad I could help.

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.