Add objects to package namespace Add objects to package namespace r r

Add objects to package namespace


Along the line of @Hadley's solution, but using the environment of the namespace, how about:

environment(myfun) <- asNamespace('stats')


Why not just set the environment of your new function to the right place?

myfun <- function(x) print(x)environment(myfun) <- as.environment("package:stats")


You can access internal objects of a package using the triple colon operator :::. Take a look at, for example, as.roman and utils:::.roman2numeric. (Compare this to utils::.roman2numeric.) This could help you avoid having to put your function inside the namespace.

You might also want to look at dont.lockBindings in the mvbutils package, which stops namespaces being locked.