Skip to content

Commit

Permalink
adjusting onLoad and test suite for winbuilder
Browse files Browse the repository at this point in the history
  • Loading branch information
tkonopka committed Mar 6, 2020
1 parent d1a3e60 commit 0923209
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 13 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: umap
Title: Uniform Manifold Approximation and Projection
Version: 0.2.4.2
Version: 0.2.5.0
Authors@R:
person("Tomasz", "Konopka", , "[email protected]", role = c("aut", "cre"))
Author: Tomasz Konopka [aut, cre]
Expand Down
21 changes: 13 additions & 8 deletions R/umap.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,31 @@
NULL


# These lines are required to control access to the umap python module
#
# For interfacing with python and "umap-learn"
#' @importFrom reticulate py_module_available import
NULL


# This implements a "soft" requirement for python and the umap module
# i.e. the package should work when those components are absent
# but gain additional functionality when those components are present
#' interface to umap-learn via reticulate
#'
#' @keywords internal
#' @noRd
#' @importFrom reticulate py_module_available import
python.umap = NULL
.onLoad = function(libname, pkgname) {
has.pkg.umap = reticulate::py_module_available("umap")
if (has.pkg.umap) {
# assignment in parent environment!
# this "try" block is necessary because:
# a system that python but not umap-learn stops during the test suite
# with the following sequence of commands (devtools)
# document(); test(); test()
# note that test() only fails at second round
try({
python.umap <<- reticulate::import("umap", delay_load=TRUE)
}
}, silent=TRUE)
}


#' Default configuration for umap
#'
#' A list with parameters customizing a UMAP embedding. Each component of the
Expand Down
14 changes: 10 additions & 4 deletions tests/testthat/test_python.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,16 @@ rownames(d.test) = paste0("Test", seq_len(nrow(d.test)))
# Only test if umap is available as python package


if (reticulate::py_module_available("umap")) {
# Note: a more elegant approach with skip() does not seem to work
# devtools::test() stops when skip() is invoked

# this "try" block is necessary because:
# a system that does not have python at all will generate a warning,
# which can generate a NOTE during R CMD check (winbuilder)
has.umap.learn = FALSE
try({
has.umap.learn = reticulate::py_module_available("umap")
}, silent=TRUE)


if (has.umap.learn) {
# create initial embedding
u1 = umap(d.train, method="umap-learn", n_neighbors=10)

Expand Down

0 comments on commit 0923209

Please sign in to comment.