Error message from `devtools::check()` says "Running examples in ‘packagename-Ex.R’ failed"—why?

Responding to an old thread "Use check() and get error about *-Ex.R," because it's a real bummer when you find post in an Internet forum by a person who had the exact same problem as you, locked, with no answer.

The original poster saw an error message similar to this when running devtools::check(), or possibly when clicking on the BuildCheck button in RStudio:

❯ checking examples ... ERROR
  Running examples in ‘add2md-Ex.R’ failed
  The error most likely occurred in:
  > base::assign(".ptime", proc.time(), pos = "CheckExEnv")
  > ### Name: hello
  > ### Title: Hello, World!
  > ### Aliases: hello
  > ### ** Examples
  > hello()
  Error in hello() : could not find function "hello"
  Execution halted

The only person to respond to the thread suggested looking for a file called add2md-Ex.R.

That was incorrect advice. No such file exists; check() seems to be creating that file on-the-fly in order to run code within an @examples Roxygen directive in one of the source files.

The solution is to look for

#' @examples
#' hello()

in the code and update that so it's calling valid functions on valid data.

I am not that familiar with R, packaging for R, or Roxygen2—yet—so if I've gotten some of the terminology wrong, I'd appreciate a heads-up.

Sorry I didn't get to your post sooner, DenverCoder9, I mean @EconKid. I hope you figured it out.

See also