I'm using devtools to develop an R package and I'm having trouble with my @examples. I can't believe it, but currently I'm in a place where if I add or remove a comment from the example, it will either check() with no errors, or halt with what seems like an impossible error, or at least one that seems impossible to relate to my code.
This example check()'s with no errors:
#' @examples
#' jetsh = read_net(iac_example("jets_sharks.yaml"))
#' jetsh = set_external(jetsh, "Ken", 1.0)
#' jetsh = iac::cycle(jetsh, ncycles = 100)
#' #
#' plot_log(jetsh, roi=c("Ken", "_Ken", "jets", "sharks", "burglar", "bookie"),
#' main="Ken is a burgling Shark")
But the version below fails! Note the longer comment about Ken. I've replicated this several times, including restarting the R session between check()'s
#' @examples
#' jetsh = read_net(iac_example("jets_sharks.yaml"))
#' jetsh = set_external(jetsh, "Ken", 1.0)
#' jetsh = iac::cycle(jetsh, ncycles = 100)
#' # Ken is a burglar in the Sharks, what is retrieved from his name
#' plot_log(jetsh, roi=c("Ken", "_Ken", "jets", "sharks", "burglar", "bookie"),
#' main="Ken is a burgling Shark")
The error message from R CMD CHECK doesn't seem relevant. I've seen scattered reports of similar errors, but not this one:
> base::assign(".dptime", (proc.time() - get(".ptime", pos = "CheckExEnv")), pos = "CheckExEnv")
> base::cat("read_net", base::get(".format_ptime", pos = 'CheckExEnv')(get(".dptime", pos = "CheckExEnv")), "\n", file=base::get(".ExTimings", pos = 'CheckExEnv'), append=TRUE, sep="\t")
> ### * <FOOTER>
> ###
> cleanEx()
> options(digits = 7L)
> base::cat("Time elapsed: ", proc.time() - base::g
+ Error: unexpected end of input
Execution halted
The example code runs fine regardless of check() status. Further frustrating is that I have another function using the same @examples, and it has never generated an error during check().
The non-failing version is on git-hub: 'rob-ward-psych/iac'
(read_net()
in the file iac_network.R
). Any help running this down is greatly appreciated.
That looks like a devtools::check
bug. I get the same error as you using devtools::check
, but if I build the .tar.gz
file and then run
R CMD check iac_0.1.0.tar.gz
I get no error. If you're using RStudio, you can default to the standard check method in a project option: uncheck Build tools | Use devtools package functions if available
.
EDITED to add:
I did some debugging of devtools::check
to find out what was going wrong. I don't think this is actually a devtools::check
bug. It calls the regular R CMD check
with the --timings
option; if I add that option when I call R CMD check
directly, I get the same error. It appears to be triggered because the iac_example()
function has a call to file.edit()
in its examples section. I don't know why the form of the comment makes a difference, but it would generally be a good idea to make the call to file.edit()
conditional on interactive execution, i.e. write
if (interactive())
file.edit(iac_example("what_where.yaml"))