r-lib / roxygen2

Generate R package documentation from inline R comments
https://roxygen2.r-lib.org
Other
594 stars 233 forks source link

give better error message when erroneously using @example #494

Closed maxheld83 closed 8 years ago

maxheld83 commented 8 years ago

I erroneously wrote @example instead of @examples before, well, an actual example (I'm guessing this happens easily).

Because @example expects a file afterwards as per r-pkgs:

When you use ?add, help("add"), or example("add"), R looks for an .Rd file containing \alias{"add"}.

the whole documentation (and build) failed, because of this section:

#' @example
#' dataset <- civicon_2014$sorts[,,"before"]
#' diag_forced(dataset = dataset,
#'             grid = diag_distro_max(dataset))

This is to be expected, of course, but it took me a quite a while to figure out what the problem was, because the error message is not every informative (I think):

Updating pensieve documentation
Loading pensieve
Error in file(con, "r") : cannot open the connection
Calls: suppressPackageStartupMessages ... process_examples -> unlist -> lapply -> FUN -> file
In addition: Warning message:
In file(con, "r") :
  cannot open file '/Users/Max/GitHub/pensieve/dataset <- civicon_2014$sorts[,,"before"]
diag_forced(dataset = dataset,
            grid = diag_distro_max(dataset))': No such file or directory
Execution halted

Exited with status 1.

Any chance there might be a more informative error message and/or protection against this mistake?

It's now easy for me to see that of course /Users/Max/GitHub/pensieve/dataset <- civicon_2014$sorts[,,"before"]diag_forced(dataset = dataset, grid = diag_distro_max(dataset))' isn't a file, it was somehow hard to see in the printout unless you knew what you were looking for.

Or maybe I'm just unusually dense.

hadley commented 8 years ago

That frequently messes me up too. Hopefully the new warning is more informative.