example code produces different results when executed using devtools::run_examples or devtools::check

I am trying to understand why the code included in the @examples section of a package I am working on produces different outputs depending if it runs using devtools::run_exmaples() or devtools::check()

From time to time I included in the example code like, e.g.:
stopifnot(nrow(x) == 5540)

When I run the code by copy pasting it into the R console it produces NO errors, If I run it using devtools::run_examples() there are no errors, however when the examples are executed using devtools::check() or R CMD check the example check fails with:

> stopifnot(nrow(x) == 5540)
Error: nrow(x) == 5540 is not TRUE

What might be the reason for it? What should I look into? are the examples run in a different environment? Is it the order of the examples that changes? Are there side effects? Is it possible that the lib.path is different?

It could be a number of things, but it is difficult to speculate without more information unfortunately. I would encourage you to try to isolate the differences, and see what x looks like in both cases.

1 Like

Dear Jim,

Thank you. I followed your idea to have a look at x. I came up writing the x into a file when executing the run_examples and check commands, and then comparing them.
Below I show the start of the example code.
LFQService::ionstar is an R6 object that resides in the package's data directory and contains some example data, which I assign to the variable bb. To my surprise, the variable bb differs, depending on if I run the check or the examples. This difference explains the difference in the example result. However, no idea why the data changes!?

Is it possible that clean_Ex() works differently in the run_examples and check?

I am speculating that it is an R6 class reference semantics, and clean_Ex(), when executed from the check, does not remove the LFQService::ionstar; hence LFQService::ionstar is not loaded from disc, but some version changed in one of the previous examples is used.

### ** Examples

library(tidyverse)
library(LFQService)

bb <- LFQService::ionstar$filtered()
saveRDS(bb, file="c:/Temp/__debugR/aaaaa.rds")

This topic was automatically closed after 45 days. 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.