Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

winbuilder's note on namespaces #730

Closed
tkonopka opened this issue Mar 3, 2020 · 3 comments
Closed

winbuilder's note on namespaces #730

tkonopka opened this issue Mar 3, 2020 · 3 comments

Comments

@tkonopka
Copy link

tkonopka commented Mar 3, 2020

Hello reticulate -

I maintain a package that uses reticulate to offer an optional feature, here. This works great for me, but recently started giving a 'note' through cran's winbuilder service.

For background, my package uses .onLoad following your advice. Because the python feature is nonessential, my .onLoad first checks if a python module is available using reticulate::py_module_available and then imports it using reticulate::import.

On the winbuilder service at CRAN, the package now takes a very long time to install (several hours) and generates a 'note' about namespaces.

** checking whether the namespace can be loaded with stated dependencies ... NOTE
Warning in system2(command = python, args = paste0("\"", config_script,  :
  running command '"C:/Users/CRAN/AppData/Local/r-miniconda/envs/r-reticulate/python.exe" "d:/RCompile/CRANpkg/lib/3.6/reticulate/config/config.py"' had status 2

A namespace must be able to be loaded with just the base namespace
loaded: otherwise if the namespace gets loaded by a saved object, the
session will be unable to start.

I do not see this note on travis and on a linux system (R 3.6.1-3). Have you encountered this, and could you offer some tips please? Thanks.

@kevinushey
Copy link
Collaborator

The problem is that this line:

https://github.com/tkonopka/umap/blob/master/R/umap.R#L33

forces reticulate to initialize Python. You should only use reticulate::import() here.

@tkonopka
Copy link
Author

tkonopka commented Mar 6, 2020

Thank you!

Turned out a one-line onLoad still gave me the same note on winbuilder. But the explanation put me on the right track and after a few more tries, I found something similar that worked.

In the R directory (using 'scipy' in this example):

# python 'scipy' module
scipy <- NULL
.onLoad <- function(libname, pkgname) {
  try({
    scipy <<- import("scipy", delay_load = TRUE)
  }, silent = TRUE)
}

And in the test suite:

# determine if the system has 'python' as well as 'scipy'
has_scipy <- FALSE
try({
  has_scipy <- reticulate::py_module_available("scipy")
}, silent = TRUE)

# run test suite
if (has_scipy) {
  test_that("Things work as expected", {
    # test code here...
  })
  # more test cases here ...
}

Without the try in onLoad, the sequence document(); test(); test(); from devtools stops when the system has python but does not have 'scipy'.

The try in the test suite seems to have no consequence on a computer with python. But it could be helping to avoid a warning in winbuilder.

@tkonopka
Copy link
Author

tkonopka commented Mar 7, 2020

With a few more tests, it appears that winbuilder now tolerates cases without the try blocks, including versions that generated a note earlier. So this issue may have been a temporary glitch.

In any case, thank you very much for your help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants