1- Sys.unsetenv(" RETICULATE_PYTHON" )
2- library(reticulate )
3- virtualenv_create(" ClustAssess-env" , packages = c(" numpy" , " clusim" , " ClustAssessPy" ))
4- use_python(" ~/.virtualenvs/ClustAssess-env/bin/python" )
5- use_virtualenv(" ClustAssess-env" , required = TRUE )
6-
71test_that(" ECS is between 0 and 1" , {
82 set.seed(1234 )
93 for (i in seq_len(100 )) {
@@ -50,6 +44,14 @@ test_that("`element_sim` produces the average of `element_sim_elscore`", {
5044})
5145
5246test_that(" ECS produces consistent results with clusim" , {
47+ testthat :: skip_on_cran()
48+ testthat :: skip_if(! requireNamespace(" reticulate" , quietly = TRUE ), " Package `reticulate` not installed" )
49+ testthat :: skip_if(! is.null(Sys.getenv(" RETICULATE_PYTHON" )), " Python environment not set" )
50+ testthat :: skip_if(
51+ ! reticulate :: py_module_available(" clusim" ),
52+ " Packages `clusim` not installed"
53+ )
54+
5355 csim <- import(" clusim" )
5456
5557 set.seed(1234 )
@@ -62,13 +64,22 @@ test_that("ECS produces consistent results with clusim", {
6264 cl1 $ from_membership_list(x )
6365 cl2 <- csim $ clustering $ Clustering()
6466 cl2 $ from_membership_list(y )
65- ecs2 <- csim $ sim $ element_sim_elscore(cl1 , cl2 )[[1 ]]$ tolist( )
67+ ecs2 <- as.numeric( csim $ sim $ element_sim_elscore(cl1 , cl2 )[[1 ]])
6668
6769 expect_equal(ecs1 , ecs2 )
6870 }
6971})
7072
7173test_that(" ECS produces consistent results with ClustAssessPy" , {
74+ testthat :: skip_on_cran()
75+ testthat :: skip_if(! requireNamespace(" reticulate" , quietly = TRUE ), " Package `reticulate` not installed" )
76+ testthat :: skip_if(! is.null(Sys.getenv(" RETICULATE_PYTHON" )), " Python environment not set" )
77+ testthat :: skip_if(
78+ ! (reticulate :: py_module_available(" numpy" ) &&
79+ reticulate :: py_module_available(" ClustAssessPy" )),
80+ " Packages `numpy` and `ClustAssessPy` not installed"
81+ )
82+
7283 np <- import(" numpy" )
7384 cpy <- import(" ClustAssessPy" )
7485
@@ -77,7 +88,7 @@ test_that("ECS produces consistent results with ClustAssessPy", {
7788 x <- sample.int(10 , size = 100 , replace = TRUE )
7889 y <- sample.int(10 , size = 100 , replace = TRUE )
7990 ecs1 <- element_sim_elscore(x , y )
80- ecs2 <- py_to_r(cpy $ element_sim_elscore(np $ array (x ), np $ array (y ))$ tolist( ))
91+ ecs2 <- as.numeric( py_to_r(cpy $ element_sim_elscore(np $ array (x ), np $ array (y ))))
8192
8293 expect_equal(ecs1 , ecs2 )
8394 }
0 commit comments