Devtools::check() errors with ggplot2 and gganimate

Before introducing animations with "ggplot2", "gganimate", ... into my R package document, devtools::check() returned no errors, warnings or notes. Now, I am receiving the following message:

### ** Examples
> cfanim(60, 3, 30, 0.25)
Error in theme_set(theme_bw()) : could not find function "theme_set"
Calls: cfanim
Execution halted.

My function "cfamin" generates an animation. The reasons given in the log are:

no visible global function definition for ‘gganimate’
Undefined global functions or variables:
  aes geom_line geom_point gganimate ggplot theme_bw theme_set x.

I suspect the problem occurs because "roxygen2" is unable to (1) add it or (2) suggest that these them to be added to the DESCRIPTION file. This is what I expect to see:

importFrom("stats", "rnorm")
importFrom("stats", "sd")
importFrom("graphics", "text")
importFrom("stats", "rlnorm")
importFrom("grDevices", "dev.hold")
importFrom("utils", "install.packages")

I have used devtools::use_package("XXX") to install them and have the Oxygen options checked to generate Rd, collate field, NAMESPACE and vignettes automatically when running, R CMD check, source and binary builds and build and reload. Furthermore, according to Wickham Hadley's book, these packages should be listed in the DESCRIPTION file. They are:


I am stumped. Any help would be greatly appreciated.

This board is primarily for RStudio IDE specific questions, as opposed to more general R + R package questions. You might consider posting this instead in the tidyverse community board.

I have done some digging and I believe the primary cause of my problem is the animation package. It wants to use magick. It cannot find it so the function searches for ImageMagic. It cannot find it either because ImageMagicis not available for R version 3.4.2. Incidentally, I used HomeBrew to install it on computer, therefore it would have solved problem if it was not incompatable with R. Yihue Xie, the author of animation is aware of the problem and promises to update the package with`magick.'

I made some changes my code since publishing my post. Regardless, devtools::check() gives a new error:

Error in ggplot(df, xlim = xlim, ylim = ylim, col = gray(0.5)) : 
  could not find function "ggplot"
Calls: cfanim
Execution halted

Even with this error and other warnings and notes, my script successfully produces an animation. R Markdown produces an animation with several comments that seem to be unrelated to the devtools::check() output.

It is much easier to fix problems if the package you are writing is public.

However in your examples it looks as though you are calling ggplot2 functions without loading the ggplot2 package first.