Unit testing for non-working internet connection

When reading CRAN section of the current R Journal (https://journal.r-project.org/archive/2018-2/cran.pdf) I have noticed that CRAN packages depending on Internet resources are now expected to fail gracefully with message (and not an error or warning) if internet resources are unavailable.

I maintain a package which I ought to update in this manner (at present it throws an error with stop('No internet connection or data source broken.').

This brings me to a more general question, namely that I would prefer to have this behaviour a part of unit tests (I use Travis running testthat and covr::codecov()). I am however not aware of a technique how to trick testthat on Travis into an offline mode.

Any advice on creating such a unit test are highly appreciated!


Create a dummy envir variable that mimics no connection and then build a skip_no _connection() based on that variable. Then manipulate the ci by manually turning on the envir variable.

here is an example of doing this with the clipboard that i use in {carbonate} that i saw on {reprex} to mimic a failed message for clipboards on the ci.


It took me a while to wrap my head about the idea - but thanks, it works now.

I ended up amending the if() clause that test the resource availability to include OR to a logical environment variable that simulates the network down.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.