R/package.R

Defines functions .onLoad

#-------------------------
# Load the python-modules
#-------------------------


RGF_mod <- NULL; RGF_utils <- NULL; SCP <- NULL;


.onLoad <- function(libname, pkgname) {

  #---------------------------------------------------------------------------  keep these lines for debugging
  # print(reticulate::py_discover_config())               # it throws an error
  #
  # see the following issues / references:
  #  - https://github.com/rstudio/reticulate/issues/394
  #  - https://github.com/rstudio/reticulate/issues/292#issuecomment-399208184
  #  - https://github.com/rstudio/reticulate/issues/568#issuecomment-517926879
  #  - https://rdrr.io/github/kojikoji/ptcomp/src/R/zzz.R
  #  - http://r-pkgs.had.co.nz/r.html                       # usage of .onLoad
  #
  # available conda environments:
  # print(reticulate::conda_list(conda = "auto"))
  #               name                                                  python
  # 1  Miniconda36-x64                         C:\\Miniconda36-x64\\python.exe
  # 2 test-environment C:\\Miniconda36-x64\\envs\\test-environment\\python.exe
  # force reticulate to use the desired conda environment:
  # reticulate::use_condaenv('test-environment', required = TRUE)
  #---------------------------------------------------------------------------

  try({                                                                                # I added this try() function in version 1.0.7 because I received a similar warning as mentioned in: [ https://github.com/rstudio/reticulate/issues/730 ] and [ https://github.com/rstudio/reticulate/issues/814 ]

    if (reticulate::py_available(initialize = TRUE)) {

      if (reticulate::py_module_available("rgf.sklearn")) {

        RGF_mod <<- reticulate::import("rgf.sklearn", delay_load = TRUE)
      }
      # else {
      #   packageStartupMessage("The 'rgf.sklearn' module is not available!")          # keep these lines for debugging
      # }

      if (reticulate::py_module_available("rgf.utils")) {

        RGF_utils <<- reticulate::import("rgf.utils", delay_load = TRUE)
      }
      # else {
      #   packageStartupMessage("The 'rgf.utils' module is not available!")            # keep these lines for debugging
      # }

      if (reticulate::py_module_available("scipy")) {

        SCP <<- reticulate::import("scipy", delay_load = TRUE, convert = FALSE)
      }
      # else {
      #   packageStartupMessage("The 'scipy' package is not available!")                # keep these lines for debugging
      # }
    }
    # else {
    #   packageStartupMessage("Python is not available!")                              # keep these lines for debugging
    # }

  }, silent=TRUE)
}
mlampros/RGF documentation built on March 17, 2021, 1:50 p.m.