Hello developers, I am wondering if base packages whose functions are used in my package need to be present in Imports in my DESCRIPTION. For example, if I use the function abline(), which exists in the *graphics* package, do I need to include *graphics* in Imports? Note I am not asking about whether I need to import all or any function from the *graphics* package, that is, assume I am using graphics::abline(), etc. I am solely asking about the DESCRIPTION file, not the Namespace. I ask because there seems to be some ambiguity about this. I received a pull request from someone adding *methods* to my Imports after noticing I didn't declare it when using a function from *methods* (accessed in my package using ::). Looking on StackOverflow, there seems to be confusion about this. The most relevant question I could find was this one <https://stackoverflow.com/q/39439006/6348551>. The question was marked as a duplicate despite the linked duplicate being separate from it (i.e., asking about the Namespace, not the DESCRIPTION). Similarly, the answer to the question does not address the question, again referring to the Namespace and making an irrelevant distinction between Depends and Imports. Some of the comments reference a CRAN policy, and yet that policy does not seem to be implemented since many packages (including all of mine) omit the base packages from the DESCRIPTION. So, is it optional to include these packages in the DESCRIPTION? I see some packages do so and some don't. Is including these packages filling the DESCRIPTION with unnecessary dependencies that are automatically satisfied, or is it being helpfully explicit about the packages your package relies on? Thanks. Noah
[R-pkg-devel] Should 'methods' be in Imports?
6 messages · Noah Greifer, Duncan Murdoch, Ivan Krylov
I think the Writing R Extensions manual is pretty clear about this: yes, you should include "methods" in Imports or Depends if you are calling methods::<fn>. You say "some packages do so and some don't". Which ones don't? It's helpful to be specific in your examples. Duncan Murdoch
On 16/03/2023 11:29 a.m., Noah Greifer wrote:
Hello developers, I am wondering if base packages whose functions are used in my package need to be present in Imports in my DESCRIPTION. For example, if I use the function abline(), which exists in the *graphics* package, do I need to include *graphics* in Imports? Note I am not asking about whether I need to import all or any function from the *graphics* package, that is, assume I am using graphics::abline(), etc. I am solely asking about the DESCRIPTION file, not the Namespace. I ask because there seems to be some ambiguity about this. I received a pull request from someone adding *methods* to my Imports after noticing I didn't declare it when using a function from *methods* (accessed in my package using ::). Looking on StackOverflow, there seems to be confusion about this. The most relevant question I could find was this one <https://stackoverflow.com/q/39439006/6348551>. The question was marked as a duplicate despite the linked duplicate being separate from it (i.e., asking about the Namespace, not the DESCRIPTION). Similarly, the answer to the question does not address the question, again referring to the Namespace and making an irrelevant distinction between Depends and Imports. Some of the comments reference a CRAN policy, and yet that policy does not seem to be implemented since many packages (including all of mine) omit the base packages from the DESCRIPTION. So, is it optional to include these packages in the DESCRIPTION? I see some packages do so and some don't. Is including these packages filling the DESCRIPTION with unnecessary dependencies that are automatically satisfied, or is it being helpfully explicit about the packages your package relies on? Thanks. Noah [[alternative HTML version deleted]]
______________________________________________ R-package-devel at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-package-devel
Thank you for your input. *broom*, *mlogit*, *twang*, and *Hmisc* are examples of major packages that import functions from *stats*, *utils*, *graphics*, or other base packages but don't include them in the DESCRIPTION. All of my packages (*cobalt*, *WeightIt*, *MatchIt*) do too, and I have never had a message from CRAN about it. (None of these are specifically about *methods*, but as a base package I assume it should work the same as these others.) Noah
On 16/03/2023 2:21 p.m., Noah Greifer wrote:
Thank you for your input. /broom/, /mlogit/, /twang/, and /Hmisc/ are?examples of major packages that import?functions from /stats/, /utils/, /graphics/, or other base packages but don't include them in the DESCRIPTION. All of my packages (/cobalt/, /WeightIt/, /MatchIt/) do too, and I have never had a message from CRAN about it. (None of these are specifically?about /methods/, but as a base package I assume it should work the same as these others.)
broom doesn't mention stats in DESCRIPTION, but does import from it in the NAMESPACE. (I haven't checked the rest of your list.) I'm a little surprised by that, but it's understandable: the NAMESPACE does declare that stats is needed. WRE says this about Imports: "Namespaces accessed by the ?::? and ?:::? operators must be listed here, or in ?Suggests? or ?Enhances? (see below). Ideally this field will include all the standard packages that are used, and it is important to include S4-using packages." So the use of Imports for "standard packages" that are used in NAMESPACE appears to be optional but recommended. However, my understanding was that you were talking about using things like graphics::abline without importing any graphics functions via the NAMESPACE; in that case, the manual is very explicit that you would need to put graphics in Imports. That doesn't mean "R CMD check" will complain if you don't, but it does mean that it might start doing so if it doesn't already. Do you know of any examples of packages that use things like graphics::abline without mentioning graphics in either the NAMESPACE or DESCRIPTION file? Duncan Murdoch
On Thu, 16 Mar 2023 11:29:33 -0400
Noah Greifer <noah.greifer at gmail.com> wrote:
Is including these packages filling the DESCRIPTION with unnecessary dependencies that are automatically satisfied, or is it being helpfully explicit about the packages your package relies on?
Here's a comment from the part of R CMD check that checks for NAMESPACE dependencies unstated in DESCRIPTION:
Not clear whether we want to require *all* namespace package dependencies listed in DESCRIPTION, or e.g. just the ones on non-base packages. Do the latter for time being ... Actually we need to know at least about S4-using packages, since we need to reinstall if those change.
So the answer is maybe. Personally, I opt for listing even the base packages explicitly, but it's a choice. Duncan's quote from WRE hints that this may be enforced in the future. I do find it a bit strange that not listing methods as a dependency in DESCRIPTION doesn't lead to complaints from R CMD check, because it does seem that the code excludes methods (and stats4) from the list of packages that are currently okay not to declare in DESCRIPTION.
Best regards, Ivan
Thank you both for your responses. Based on Ivan's dig into the comments, it seems there is ambiguity, even by the CRAN team. Still, it looks like it would be preferable to (and would not cause any harm to) include the base packages in DESCRIPTION if they are used at all in a package, whether by :: or imported from in the Namespace. I'll update my packages accordingly. Noah