Using un-exported function from another R package?

2020-02-05 02:40发布

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?

标签: r cran
2条回答
你好瞎i
2楼-- · 2020-02-05 03:08
  • 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.
查看更多
干净又极端
3楼-- · 2020-02-05 03:20

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.

查看更多
登录 后发表回答