I have read two recent posts that discuss Depends and Imports
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
An import dependency in the implementation model is a stereotyped dependency whose source is an implementation subsystem and whose target is an implementation subsystem. The import dependency allows the public contents of the target subsystem to be referenced in the source subsystem.
Imports is used for packages that are needed by your package but that don't need to be loaded with library() . Packages referred to in @import or @importFrom statements in your Roxygen2 comments, or whose functions are accessed via the :: operator, should be here.
Dependencies are invitations for other people to break your package. — Josh Ulrich, private communication. Welcome to the seventeenth post in the relentlessly random R ravings series of posts, or R4 for short. Dependencies. A truly loaded topic.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With