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

2023-09-21 Thread Hanyu Song
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

From: Duncan Murdoch 
Sent: Thursday, September 21, 2023 6:44 AM
To: Hanyu Song ; r-package-devel@r-project.org 

Subject: Re: [R-pkg-devel] A simple question regarding examples

On 20/09/2023 8:03 p.m., Hanyu Song wrote:
> 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)
> #' }
>

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

[[alternative HTML version deleted]]

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


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

2023-09-20 Thread Hanyu Song
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

[[alternative HTML version deleted]]

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


[R-pkg-devel] Python module dependency

2023-09-01 Thread Hanyu Song
Hello,

I am writing an R package that depends on a very uncommonly used Python module 
named "ctef" and I have several questions about it:

a. How shall I write examples for the functions that depend on the Python 
module? Shall I just do:
#' @examplesIf reticulate::py_module_available('ctef')
#' my_function_that_depends_on_ctef(arg1, arg2)
in case the CRAN testing platform does not have the module?

b. I read from the documentation of the R package "reticulate" that we should 
delay load the Python modules, but it is not entirely clear to me how to do it.

Are the following lines of code sufficient for that purpose? Do I need to 
create any virtual environment?

#'  global reference to ctef
#'
#'@description
#'`ctef` will be initialized in .onLoad.
#'
ctef <- NULL

#' Delay load ctef module
#'
#' @description
#' `.onLoad` delays loading ctef module (will only be loaded when accessed via 
$).
#'
#' @param libname Library name
#' @param pkgname Package name
.onLoad <- function(libname, pkgname) {
ctef <<- reticulate::import("ctef", delay_load = TRUE)

}

c. How shall I import the module in my R code? For now I included the import 
function in my_function_that_depends_on_ctef; see below:
my_function_that_depends_on_ctef <- function(X, k) {
 mod <- reticulate::import('ctef',delay_load = TRUE)
  input <- as.matrix(X)
  res <- mod$ctef$ctef(input,as.integer(k))
return(res)
}

Is this correct?

There are not many R packages that depend on a Python module, so the resources 
are quite limited. Thank you for your help.


Best,
Hanyu Song


[[alternative HTML version deleted]]

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