Add objects to package namespace

微笑、不失礼 提交于 2019-11-27 11:07:35
Mark Bravington

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.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!