Using un-exported function from another R package?

后端 未结 2 1129
情深已故
情深已故 2020-12-03 10:48

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/s

相关标签:
2条回答
  • 2020-12-03 11:35
    • 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.
    0 讨论(0)
  • 2020-12-03 11:39

    Another trick is using getFromNamespace():

    fun <- utils::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 roxygen2 you have to add the utils package to the Imports field of your DESCRIPTION file to fulfill CRAN's requirements. Alternatively, you can put it in your NAMESPACE manually.

    0 讨论(0)
提交回复
热议问题