On Fri, 24 Sep 2021 07:49:44 -0700 Roy Mendelssohn - NOAA Federal via R-package-devel <r-package-devel@r-project.org> wrote:
> All internet calls are wrapped in 'try()'. If that shows an error, > I write a message to the screen about the error, and call stop(), > perhaps with a further message in that call. Somehow this does not > appear to meet the standard. Can someone then please tell me what > I should do instead. I think that the important part is to catch that stop() in your _tests or examples_, so that a stop() raised by a connection error inside the code of your package wouldn't fail your \example{} block or a test in tests/*.R. Good: R/myfunction.R: if (connection_failed) stop(informative_message) Bad: man/myfunction.Rd: \example{ myfunction(foo) } (During CRAN testing, connection fails, the exception reaches the R CMD check process and fails the test.) Good: man/myfunction.Rd \example{ try(myfunction(foo)) # may fail because of connection errors } Here, the exception is raised but handled. Bonus points if you use tryCatch(...) and only catch the "connection failed" conditions, allowing all other errors to propagate and still fail the tests. It's possible if you construct a condition object (x <- simpleError(...)) and append to its class(): class(x) <- c(class(x), 'connection_failed'). The resulting error can still be raised with stop(x). tryCatch() will then be able to call your handler only for connection_failed errors. Raising an exception is a valid way of dealing with connection errors for functions that rely on outside world to fulfil their promise. -- Best regards, Ivan ______________________________________________ R-package-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-package-devel