Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Imports and Depends

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

like image 238
David Diez Avatar asked Mar 27 '12 16:03

David Diez


People also ask

Are imports dependencies?

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.

What does imports mean in R package?

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.

What is a dependency in R?

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.


1 Answers

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.

like image 52
Dirk Eddelbuettel Avatar answered Nov 04 '22 14:11

Dirk Eddelbuettel