[Rd] importing namespaces from base packages

Martin Maechler maechler at stat.math.ethz.ch
Mon Mar 12 13:18:01 CET 2018

>>>>> Adrian Dușa <dusa.adrian at unibuc.ro>
>>>>>     on Fri, 9 Mar 2018 10:34:30 +0200 writes:

    > Dear All,
    > I understand the R CMD checks with only the base package attached,
    > everything else (including the other packages bundled with the base R)
    > should be imported and most importantly declared in the Imports field from
    > the DESCRIPTION file.

    > However, I do use functions from other packages than base (utils,
    > grDevices, stats, graphics), for which it is sufficient to declare
    > importFrom() in the NAMESPACE file.

    > For instance, it is not required to specify utils in the Imports: field
    > from DESCRIPTION, when using importFrom("utils", "packageDescription") in

Is that so?   Not according to my reading of the 'Writing R
Extensions' manual, nor according to what I have been doing in
all of my packages for ca. 2 years:

The rule I have in my mind is

 1) NAMESPACE Import(s|From) \
 ............................ <==>  DESCRIPTION -> 'Imports:'
 2) .. using "::" in  R code / 

If you really found that you did not have to import from say
'utils', I think this was a *un*lucky coincidence.
Even R's own  "stats" package has a line

  importFrom(utils, count.fields, flush.console, str, tail)


    > The opposite happens for importFrom("methods", "is"), which ends up in the
    > error: Namespace dependency not required: ‘methods’

    > Is there a special reason for which package methods is treated differently
    > from all other packages bundled with the base R?

    > Thank you,
    > Adrian

    > --
    > Adrian Dusa
    > University of Bucharest
    > Romanian Social Data Archive
    > Soseaua Panduri nr. 90-92
    > 050663 Bucharest sector 5
    > Romania
    > https://adriandusa.eu

There are places in the R source where it is treated specially,
indeed, part of 'methods' may be needed when it is neither
loaded nor attached (e.g., when R runs with only base, say, and
suddenly encounters an S4 object), and there still are
situations where 'methods' needs to be in the search() path and
not just loaded, but these cases should be unrelated to the
above DESCRIPTION-Imports vs NAMESPACE-Imports correspondence.

Martin Maechler
ETH Zurich & R Core Team

More information about the R-devel mailing list