diff --git a/DESCRIPTION b/DESCRIPTION index 54abbb56..2df91978 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -7,7 +7,8 @@ Authors@R: c( person("Aaron", "Lun", role = "ctb"), person("Mohamed Nadhir", "Djekidel", role = "ctb"), person("Yuhan", "Hao", role = "ctb"), - person("Dirk", "Eddelbuettel", role = "ctb") + person("Dirk", "Eddelbuettel", role = "ctb"), + person("Wouter", "van der Bijl", role = "ctb") ) Description: An implementation of the Uniform Manifold Approximation and Projection dimensionality reduction by McInnes et al. (2018) diff --git a/NEWS.md b/NEWS.md index 460d0b8a..15ab621b 100644 --- a/NEWS.md +++ b/NEWS.md @@ -9,6 +9,9 @@ been. continued to return the fuzzy graph in transposed form. Thank you [PedroMilanezAlmeida](https://github.com/PedroMilanezAlmeida) for reopening the issue (). +* Relative paths could not be used to save a model. Thank you +[Wouter van der Bijl](https://github.com/Ax3man) for the bug report +() and the suggested fix. # uwot 0.2.2 diff --git a/R/uwot.R b/R/uwot.R index 07eb462a..d8e56776 100644 --- a/R/uwot.R +++ b/R/uwot.R @@ -3956,9 +3956,9 @@ save_uwot <- function(model, file, unload = FALSE, verbose = FALSE) { # archive the files under the temp dir into the single target file # change directory so the archive only contains one directory + tmp_model_file <- abspath(file) tsmessage("Changing to ", mod_dir) setwd(mod_dir) - tmp_model_file <- abspath(file) tsmessage("Creating ", tmp_model_file) # #109: Windows 7 tar needs "--force-local" to avoid interpreting colon diff --git a/tests/testthat/test_saveload.R b/tests/testthat/test_saveload.R index dbe6d1c6..470f83ed 100644 --- a/tests/testthat/test_saveload.R +++ b/tests/testthat/test_saveload.R @@ -339,3 +339,42 @@ test_that("save-load nndescent", { unlink(mod_fname2) } }) + +# 131: can't use a relative path for saving +test_that("save-load relative path", { + set.seed(1337) + model <- umap(iris10, + n_neighbors = 4, n_epochs = 2, init = "spca", + metric = "euclidean", verbose = FALSE, n_threads = 0, + ret_model = TRUE + ) + # remember to go back to the original working directory + old_wd <- getwd() + on.exit(setwd(old_wd), add = TRUE) + + # move to a temp directory for this test + test_dir <- tempfile("test_relative_path_") + dir.create(test_dir) + setwd(test_dir) + + # Test 1: relative path no sub-folders + rel_path <- "model.uwot" + model <- save_uwot(model, file = rel_path) + expect_true(file.exists(rel_path)) + + modelload <- load_uwot(file = rel_path) + set.seed(1337) + resload_trans <- umap_transform(iris10, modelload) + expect_ok_matrix(resload_trans) + + # Test 2: Relative path within a sub-folder + dir.create("my_folder") + rel_sub_path <- file.path("my_folder", "model.uwot") + model <- save_uwot(model, file = rel_sub_path) + expect_true(file.exists(rel_sub_path)) + + modelload <- load_uwot(file = rel_sub_path) + set.seed(1337) + resload_trans <- umap_transform(iris10, modelload) + expect_ok_matrix(resload_trans) +})