Using un-exported function from another R package?

爱⌒轻易说出口 提交于 2019-12-28 13:47:07

问题


I often use utility type functions from other packages that are un-exported: pkg:::fun(). I am wondering if I can use such a function within new functionality/scope in my own R package. What is the correct approach here? Is including the package in my description file enough?


回答1:


Another trick is using getFromNamespace

fun = getFromNamespace("fun", "pkg")

The only advantage over ::: is that you don't get any NOTEs and it's allowed on CRAN. Of course this is not good practice as a hidden change in pkg can break your package.

Note: With roxygen you have to also write #' @importFrom utils getFromNamespace or put it in your NAMESPACE manually.




回答2:


  • Summarising comments from @baptise, and etc...:

  • ::: not allowed on CRAN, so options:

    1. ask author to export it so you can use it in your package via standard imports or suggests.
    2. copy / lift a version of it and clearly cite within your package.


来源:https://stackoverflow.com/questions/32535773/using-un-exported-function-from-another-r-package

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