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

2020-10-21 Thread Andy Teucher
Thanks Martin,

I agree that the example should run for a user when calling example() - hence I 
am going with a simple try() around the function calls in the examples. I agree 
your more sophisticated version has better behaviour, but I don’t want to 
clutter the examples with code that might just confuse a user.

Andy

> On Oct 21, 2020, at 12:08 AM, Martin Maechler  
> wrote:
> 
>> 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  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()
> 
> (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
> 
> __
> R-package-devel@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-package-devel

__
R-package-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-package-devel


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

2020-10-21 Thread Martin Maechler
> 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  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()

(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

__
R-package-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-package-devel


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

2020-10-20 Thread Gábor Csárdi
On Tue, Oct 20, 2020 at 10:07 PM Ben Bolker  wrote:
>
>
>
> On 10/20/20 4:51 PM, Gábor Csárdi wrote:
> > On Tue, Oct 20, 2020 at 9:45 PM Ben Bolker  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")

It is not really worth exporting this, because it just checks for an
environment variable, that's all it does. So all users would need to
set this environment variable to be able to run the examples. Which
does not seem like a great solution.

G.

__
R-package-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-package-devel


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

2020-10-20 Thread Ben Bolker




On 10/20/20 5:10 PM, Gábor Csárdi wrote:

On Tue, Oct 20, 2020 at 10:07 PM Ben Bolker  wrote:




On 10/20/20 4:51 PM, Gábor Csárdi wrote:

On Tue, Oct 20, 2020 at 9:45 PM Ben Bolker  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")


It is not really worth exporting this, because it just checks for an
environment variable, that's all it does. So all users would need to
set this environment variable to be able to run the examples. Which
does not seem like a great solution.

G.



OK, fair enough.

  Ben B.

__
R-package-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-package-devel


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

2020-10-20 Thread Gábor Csárdi
On Tue, Oct 20, 2020 at 9:45 PM Ben Bolker  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

[...]

__
R-package-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-package-devel


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

2020-10-20 Thread Andy Teucher
Our package bcdata (https://cran.r-project.org/package=bcdata) retrieves public 
data from British Columbia data services, so the examples are dependent on 
successfully hitting web resources. When we initially submitted to CRAN the 
examples were wrapped in \dontrun{}, but we were asked to change them to use 
\donttest{}.

 
Now, CRAN is running checks with _R_CHECK_DONTTEST_EXAMPLES_=true, and one of 
the examples has failed due to a changed web resource. I got an email asking me 
to fix it and reminding me of the CRAN policy:
 

  'Packages which use Internet resources should fail gracefully with an 
informative message

 if the resource is not available or has changed (and not give a check warning 
nor error).'

  This needs correction whether or not the resource recovers.

 
I would prefer that in normal use, the function calling the internet resources 
fails with an error so that the user is properly alerted. I also agree that 
these failures shouldn't cause a check error. To demonstrate the use of these 
functions in examples, is there a preferred method of ensuring that failures 
will not cause a check warning or error? Should I try to revert back to using 
\dontrun{} and plead my case? Wrap in `if interactive())`?
 

Thanks very much,

Andy Teucher

 
__
R-package-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-package-devel