[英]R package: how to make my package loading other package when I library my package
I have made my own package called "test" and I install it.我制作了自己的名为“test”的包并安装了它。 However, there exist some problem.
但是,存在一些问题。
For example, in my .R file, I use function "rowQuantiles" from other package called "matrixStats".例如,在我的 .R 文件中,我使用来自名为“matrixStats”的其他包中的函数“rowQuantiles”。
And I already add我已经添加了
import(matrixStats)
to namespace file命名空间文件
and add并添加
Imports:matrixStats (>= 0.57.0)
to description file.到描述文件。
However, whenever I library my own pakcage然而,每当我图书馆我自己的包
library(test)
The following error always comes out总是出现以下错误
could not find function "rowQuantiles"
How can I make that whenever I library my own package it will load other required packages.每当我库我自己的包时,我怎么能做到这一点,它会加载其他所需的包。 Just like the following
就像下面这样
> library(ggpubr)
Loading required package: ggplot2
Key to understand this is to understand the difference between loading a package and attaching a package.理解这一点的关键是了解加载包和附加包之间的区别。
Packages listed under Imports:
are only loaded when your package attached, ie when you do library(mypkg)
. Imports:
的包仅在您的包附加时加载,即当您执行library(mypkg)
。 In contrast, packages listed under Depends:
are loaded and attached.相反,在
Depends:
包被加载和附加。 So, if you use:所以,如果你使用:
Depends: matrixStats
then all of matrixStats functions will be on the search()
path when you package is attached.那么当您附加包时,所有matrixStats函数都将位于
search()
路径上。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.