withr icon indicating copy to clipboard operation
withr copied to clipboard

more robust with_package/local_package

Open pfuehrlich-pik opened this issue 2 years ago • 1 comments

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.

pfuehrlich-pik avatar May 31 '22 09:05 pfuehrlich-pik

Any comments on this? Maybe @jimhester ?

pfuehrlich-pik avatar Oct 25 '23 12:10 pfuehrlich-pik