[R-pkg-devel] Checking package in Windows fails

Ivan Krylov kry|ov@r00t @end|ng |rom gm@||@com
Tue Nov 16 21:22:44 CET 2021


On Mon, 15 Nov 2021 17:15:14 +0100
Ben Engbers <Ben.Engbers using Be-Logical.nl> wrote:

> I don't know why I have to explicitly include 'library("rex")' in
> the code since I have added rex to the Imports in the DESCRIPTION

Have you added the corresponding importFrom(...) [1] commands to your
NAMESPACE file?

> pi <- pingr::is_online()
> va <- grepl(re, input)

> if (pi && va && (get_URL <-httr::GET(input))$status ==200)

Theoretically, this invites a class of errors known as "time-of-check
to time-of-use" [2]: the user may go offline after the
pingr::is_online() check but before the httr::GET() request uses the
remote resource. But that's not what's causing you problems.

The problem here is that pingr's definition of "is online" differs from
"is able to fetch the URL you're testing", and I'm afraid it's
impossible to solve in the general sense. What you could do instead is
use tryCatch() to handle the error originating from curl and return
something else instead.

Or maybe letting the error propagate is the right idea. It may be bad
for reproducibility when a function silently returns something
completely different after the user goes offline. Then you would have
to handle the error in your tests instead of the function. A simple
option is wrapping the whole block of test code in try(), but that would
handle all errors, including real bugs.

A more complicated solution would be to handle the connection errors
specifically, construct error objects of class "connection_error",
signal them from the function and only handle those when testing via
tryCatch(..., connection_error = ...). This would let you both (1)
correctly propagate connection errors to the user instead of silently
returning the URL itself and (2) not crash the tests despite that.
See ?conditions for more information on that topic.

-- 
Best regards,
Ivan

[1]
https://cran.r-project.org/doc/manuals/r-release/R-exts.html#Specifying-imports-and-exports

[2] https://en.wikipedia.org/wiki/TOCTOU



More information about the R-package-devel mailing list