R/Bioconductor开发中import和depend的区别

import:将命名空间载入

depends:将命名空间载入,并且放入搜索目录。

两者在使用上的区别是:import只载入对开发者有用的,而depends需要载入对用户有用的。比如说GenomicRanges,
如果你开发的包使用到了GRanges类,并且它会成为结果返回给用户,那么你就必须使用depends了,如果你只是用了GenomicRanges中的类或者函数,比如说GRanges,
但是并没有在任何输入输出中使用到它们,那你就只需要使用import就可以了。但是在大多数情况下,GRanges是会成为输入或者输出的一部分,
所以总是倾向于使用depends的。

下面是Martin的原话:

R package symbols and other objects are collated at build time into a ‘name
space’. When used,

– Import: loads the name space from disk.
– Depends: loads the name space from disk, and attaches it to the search() path.

Attaching is very inexpensive compared to loading, so there is no speed
improvement gained by Import’ing instead of Depend’ing.

The main reason to Depend: on a package is because the symbols defined by the
package are needed by the end-user. Import’ing a package is appropriate when the
package provides functionality only relevant to the package author.

There are likely to be specific packages that mis-use Depends; packages such as
IRanges, GenomicRanges, etc use Depends: as intended, to  provide functions that
are useful to the end user.

Maintainers are certainly encouraged to think carefully about adding packages
providing functionality irrelevant to the end-user to the Depends: field. The
codetoolsBioC package (available from svn, see
http://bioconductor.org/developers/how-to/source-control/) provides some mostly
reliable hints to package authors about correctly formulating a NAMESPACE file
to facilitate using Imports: instead of Depends:.

General questions about Bioconductor packages should be addressed to the support
forum https://support.bioconductor.org.

Questions about Bioconductor development (such as this) should be addressed to
the bioc-devel mailing list (subscription required)
https://stat.ethz.ch/mailman/listinfo/bioc-devel.

发表评论

电子邮件地址不会被公开。 必填项已用*标注