Skip to content

[R-pkg-devel] A simple question regarding examples

5 messages · Hanyu Song, Duncan Murdoch, Ivan Krylov

#
Hello,

I have a simple question about including examples. My code depends on a rarely used Python module, so I am using the @examplesIf tag per Hadley Wickham's advice as follows:

#' @examplesIf reticulate::py_module_available('ctef')
#'  res <- my_func(input1, input2)

Unfortunately, my_func runs overtime during the CRAN check. To resolve this, do I simply use the less elegant approach as follows?

#' \dontrun{
#' if (reticulate::py_module_available('ctef')) {
#' res <- my_func(input1, input2)
#' }

Thank you,
Hanyu
#
On Thu, 21 Sep 2023 00:03:11 +0000
Hanyu Song <hanyu.song at duke.edu> wrote:

            
\dontrun{} is reserved for things that either cannot be guaranteed to
work (highly dependent on the user's system), involve examples of
interactive input/output (e.g. ?debugger), or are potentially too
destructive in case they break (e.g. ?connections). The \examples
section should include running code, which example(your_func) should
run. If there's only the \dontrun{} section, it won't pass the review.

For things that ought to work, it's best to reduce inputs further until
the example runs within the time limit. One remaining escape hatch is
\donttest{}, but R CMD check --as-cran still involves running
\donttest{} examples. Putting the whole example in a \donttest{}
section doesn't sound like a good idea either.
#
On 20/09/2023 8:03 p.m., Hanyu Song wrote:
The @examplesIf comments are directed at Roxygen; R checks will never 
look at them.  R will run tests based on what is in the my_func.Rd 
examples section.  I'd guess that's pretty similar to your second 
version (except for the \dontrun part, which you shouldn't use, as Ivan 
said).

Duncan Murdoch
#
Hello Duncan and Ivan,

Thank you for your prompt response! Perhaps I should add that:

I don't think the Python module "ctef" exists on CRAN. Therefore, I am very surprised that the example below runs overtime, since all it has to do is to run reticulate::py_module_available('ctef'). If even this part is running overtime, I am not quite sure how to deal with it.

#' if (reticulate::py_module_available('ctef')) {
#' res <- my_func(input1, input2)
#' }

Looking forward to your reply.

Best,
Hanyu
1 day later
#
? Thu, 21 Sep 2023 22:11:37 +0000
Hanyu Song <hanyu.song at duke.edu> ?????:
Can you show the precise message given to you by the check?

Are you able to reproduce the problem if you run R CMD check (for
example) in a virtual machine without a working Python installation?

It would explain the situation if the process was stuck asking the user
for (e.g.) permission to install miniconda, but these prompts are all
guarded by tests for interactive() and therefore shouldn't be happening.