withr
withr copied to clipboard
more robust with_package/local_package
Even if package x was already attached when calling local_package(x)
x was still detached at the end of the current execution context. This is confusing, because local_*
functions should ideally restore the same global state as before. with_package
already had a check for that, and with this PR the same check is used for local_package
. Furthermore with_package
is now implemented using local_package
to reduce code duplication. This is also removes the on.exit
that with_package
was using instead of defer
.
Any comments on this? Maybe @jimhester ?