[R-pkg-devel] Usage of internet resources in examples

Martin Maechler m@ech|er @end|ng |rom @t@t@m@th@ethz@ch
Wed Oct 21 09:08:02 CEST 2020


>>>>> Ben Bolker 
>>>>>     on Tue, 20 Oct 2020 17:07:10 -0400 writes:

    > On 10/20/20 4:51 PM, Gábor Csárdi wrote:
    >> On Tue, Oct 20, 2020 at 9:45 PM Ben Bolker <bbolker using gmail.com> wrote:
    >> [...]
    >>> if (testthat::skip_on_cran())
    >>> 
    >>> all seem like reasonable solutions.
    >> 
    >> I don't think you can use `testthat::skip_on_cran()` for this, it does
    >> not return a logical flag:
    >> 
    >> ❯ isTRUE(testthat::skip_on_cran())
    >> Error: Reason: On CRAN
    >> 
    >> It only works in testthat tests.
    >> 
    >> Gabor
    >> 
    >> [...]
    >> 

    > oh OK, sorry.  The guts of the function are (in testthat:::on_cran(), 
    > which can't be used because it's not exported)

    > !identical(Sys.getenv("NOT_CRAN"), "true")

I still disagree with that part of your recommendations, for this reason:
I think a "perfect" solution would keep the example(s) running
fine when the user calls

     example(<topic>)

(hence it is very good recommendation to  *not* misuse \dontrun{.} here)
*and* have the   example(.)  call  *not* stop on error, but (say)
produce a warning in the case the internet connection isn't
stable at the time the user calls   example(.),
e.g., myself in a train ride in the Swiss alps ..

Hence, your (Ben's) first two suggestions make more sense to me,
and I'd clearly favor

	try(.)

or possibly slightly more sophsticated versions such as

      if(inherits(try({
         .......
         }), "try-error"))  warning(....)

Or then your 2nd suggestion,  if(interactive())
in the case (as it seems here) where the package author
really wants the user to get an error when the internet
connection fails.


Martin



More information about the R-package-devel mailing list