diff --git a/R/loaded.r b/R/loaded.r index 39d99e67..4d9d2ead 100644 --- a/R/loaded.r +++ b/R/loaded.r @@ -41,7 +41,11 @@ register_mod = function (info, mod_ns) { #' @rdname loaded deregister_mod = function (info) { - rm(list = info$source_path, envir = loaded_mods) + # May already have been removed if called by `unload_mod_recursive`, where + # a given module is imported by multiple submodules. + if (exists(info$source_path, envir = loaded_mods)) { + rm(list = info$source_path, envir = loaded_mods) + } } #' @rdname loaded diff --git a/tests/testthat/mod/reload/nested/a.r b/tests/testthat/mod/reload/nested/a.r new file mode 100644 index 00000000..2fdd52f7 --- /dev/null +++ b/tests/testthat/mod/reload/nested/a.r @@ -0,0 +1 @@ +box::export() diff --git a/tests/testthat/mod/reload/nested/b.r b/tests/testthat/mod/reload/nested/b.r new file mode 100644 index 00000000..fe779e2a --- /dev/null +++ b/tests/testthat/mod/reload/nested/b.r @@ -0,0 +1,3 @@ +box::use(./a) + +box::export() diff --git a/tests/testthat/mod/reload/nested/c.r b/tests/testthat/mod/reload/nested/c.r new file mode 100644 index 00000000..acf2fc98 --- /dev/null +++ b/tests/testthat/mod/reload/nested/c.r @@ -0,0 +1,3 @@ +box::use(./a, ./b) + +box::export() diff --git a/tests/testthat/test-reload.r b/tests/testthat/test-reload.r index d04b3e8f..16fa23a3 100644 --- a/tests/testthat/test-reload.r +++ b/tests/testthat/test-reload.r @@ -115,3 +115,9 @@ test_that('`reload` shows expected errors', { '"reload" expects a module object, got "x", which is of type "integer" instead' ) }) + +test_that('reloading a module used twice does not cause a warning', { + box::use(mod/reload/nested/c) + + expect_warning(box::reload(c), NA) +})