What are some use cases for assignInMyNamespace?

Viewed 225

I would like to know of some packages that make use of assignInMyNamespace and what it's used for, if it is even advisable to use this function in production code. The help page gives the following information:

assignInMyNamespace is intended to be called from functions within a package, and chooses the namespace as the environment of the function calling it.

However it also gives the following warning about assignInNamespace:

assignInNamespace should not be used in final code, and will in future throw an error if called from a package. Already certain uses are disallowed.

Presumably this is because packages shouldn't ever try to change the namespaces of other packages, which is why the warning doesn't apply to assignInMyNamespace. Is this true?

NB: I am developing a package with an unexported testing function that allows any unexported function in the package to be temporarily replaced with one that saves its inputs and outputs. I am also considering such a technique for switching between memoised / un-memoised versions of functions.

EDIT: In practise, assignInMyNamespace only changes unexported functions - not 'any function in the package' as previously stated. I only realised this recently, and it's actually thrown a spanner in the works with the package I'm developing. Therefore I would also be very interested to know if there is a solution to the problem that works across both exported and unexported functions during package use.

0 Answers
Related