Using un-exported function from another R package?

2020-02-05 03:09发布

问题:

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.


标签: r cran