问题
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:
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.)
Is it okay to specify a package in both the Depends and Imports fields?
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?
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:
"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.
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.
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