Imports and Depends

北城余情 提交于 2019-12-20 10:28:16

问题


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. 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.)

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

  3. 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?

  4. 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.

Thanks much!

David


回答1:


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. "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.

  2. 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.

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

  4. 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.



来源:https://stackoverflow.com/questions/9893791/imports-and-depends

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!