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:- ask author to export it so you can use it in your package via standard imports or suggests.
- copy / lift a version of it and clearly cite within your package.