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?
我经常使用其他未导出的包中的实用程序类型函数:pkg ::: fun()。我想知道我是否可以在我自己的R包中的新功能/范围内使用这样的功能。这里的正确方法是什么?包含在我的描述文件中的包够吗?
2 个解决方案
#1
11
Another trick is using getFromNamespace
另一个技巧是使用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,并且它在CRAN上是允许的。当然这不是一个好习惯,因为pkg的隐藏变化可能会打破你的包裹。
Note: With roxygen you have to also write #' @importFrom utils getFromNamespace
or put it in your NAMESPACE manually.
注意:使用roxygen,您还必须编写#'@ importFrom utils getFromNamespace或手动将其放入NAMESPACE。
#2
10
-
Summarising comments from @baptise, and etc...:
总结来自@baptise等的评论...:
-
:::
not allowed on CRAN, so options::::不允许使用CRAN,所以选项:
- 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.
- 复制/提升它的一个版本并清楚地引用你的包裹。
#1
11
Another trick is using getFromNamespace
另一个技巧是使用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,并且它在CRAN上是允许的。当然这不是一个好习惯,因为pkg的隐藏变化可能会打破你的包裹。
Note: With roxygen you have to also write #' @importFrom utils getFromNamespace
or put it in your NAMESPACE manually.
注意:使用roxygen,您还必须编写#'@ importFrom utils getFromNamespace或手动将其放入NAMESPACE。
#2
10
-
Summarising comments from @baptise, and etc...:
总结来自@baptise等的评论...:
-
:::
not allowed on CRAN, so options::::不允许使用CRAN,所以选项:
- 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.
- 复制/提升它的一个版本并清楚地引用你的包裹。