pkgload icon indicating copy to clipboard operation
pkgload copied to clipboard

duplicate namespaces

Open moodymudskipper opened this issue 3 months ago • 1 comments

I got into a situation that can be simplified like this :

# in development with devtools
old_ns <- asNamespace("mypkg")
pkgload::load_all()
#> ℹ Loading mypkg
new_ns <- asNamespace("mypkg")
old_ns
#> <environment: namespace:mypkg>
new_ns
#> <environment: namespace:mypkg>
identical(old_ns, new_ns)
#> [1] FALSE

(and then had some code evaluating in the wrong not reloaded namespace)

I first though load_all() could repopulate the namespace rather than creating a new one, but we could for instance have a binding to old_ns$some_env and new_ns might not even have some_env so that won't work.

Maybe we could have a warning (in unload() ?) that the old namespace couldn't be garbage collected, presumably because some objects are still pointing to it, and advise to restart the session if it was not intended ?

moodymudskipper avatar Mar 28 '24 15:03 moodymudskipper

Unfortunately I don't think we can easily improve on the current behaviour.

lionel- avatar Mar 28 '24 15:03 lionel-