进口和取决于 [英] Imports and Depends

查看:184
本文介绍了进口和取决于的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已阅读最近两篇讨论取决于和进口的帖子

I have read two recent posts that discuss Depends and Imports

  • Upcoming NAMESPACE, Depends, Imports changes for 2.14.0 (some definitions/use please)
  • Better explanation of when to use Imports/Depends

但我有四个挥之不去的相关问题:

But I have four lingering, related questions:


  1. 假设我希望最终用户在我的软件包中加载时也可以使用两个软件包。在这种情况下,是否有充分的理由不使用Depends? (这里的要点是通过只加载一个包的命令加载所有三个包。)

  1. Suppose I want two packages to also be available to the end-user when they load in my package. Is there a good reason not to use Depends in this context? (The point here is to load all three packages via a command that loads just the one package.)

是否可以在两个包中指定包和Imports字段?

Is it okay to specify a package in both the Depends and Imports fields?

如果在Depends中列出了一个包,是否还要在Imports中列出它?或者使用Depends已经取消了Imports的好处?

If a package is listed in Depends, is there a point to also listing it in Imports? Or are the benefits of Imports already negated by using Depends?

以下是否正确?当且仅当在NAMESPACE文件中导入(全部或部分)包时,才应在DESCRIPTION文件的Imports字段中列出包。

Is the following correct? A package should be listed in the Imports field of the DESCRIPTION file if and only if the package is imported (in whole or in part) in the NAMESPACE file.

非常感谢!

David

推荐答案

有几点,我承认有时候我也觉得这很混乱。但我最近重新审视过,这是我的看法:

Couple of points, and I will admit that I also find this confusing at times. But I revisited it recently, and here is my take:


  1. 取决于我们以前做事的方式;它最接近只加载所有三个:当你的第三个取决于其他两个时,所有三个都将被加载。

  1. "Depends" is how we used to do things; it is closest to "just loading all three":when your third depends on the other two, all three will get loaded.

使用命名空间,我们也可以进口。这只带来了所述符号,可以是数据或函数。我有时会用它;它不会加载您导入的其他包,只是使所述符号可用。因此,它比Depends更轻。

With Namespaces, we can also import. That brings in just the stated symbols, which can be data or functions. I use this sometimes; it will not load the other package that you import from but just make the stated symbols available. As such, it is "lighter" than Depends.

如果你需要,则不需要进口。

If you do Depends, there is no need for Imports.

这是正确的:如果您在NAMESPACE中使用声明从其他包导入符号,则需要在导入中列出其他包:在描述文件中。

That is correct: If you use declarations in in NAMESPACE to import symbols from another packages, that other package needs to be listed in Imports: in the DESCRIPTION file.

这篇关于进口和取决于的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆