[R-pkg-devel] Python module dependency

Vladimir Dergachev vo|ody@ @end|ng |rom m|nd@pr|ng@com
Fri Sep 1 16:51:46 CEST 2023


Have you consider translating ctef into R ?

This would remove the dependencies and make your package much more robust.
And would make it much easier to pass CRAN checks.

Looking at ctef code it is pure Python and there aren't many lines. And in 
my experience, one line of R is worth 10 lines of Python :)

Also, ctef has a dependency on KMeans, so translating ctef into R will 
remove that too.

best

Vladimir Dergachev

On Fri, 1 Sep 2023, Hanyu Song wrote:

> 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 using r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-package-devel
>



More information about the R-package-devel mailing list