[Rd] Re R CMD check checking in development version of R

Hadley Wickham h.wickham at gmail.com
Thu Aug 28 01:24:11 CEST 2014


On Wed, Aug 27, 2014 at 5:01 PM, Gavin Simpson <ucfagls at gmail.com> wrote:
>
> On 27 August 2014 15:24, Hadley Wickham <h.wickham at gmail.com> wrote:
>>
>> > Is that the cause of these NOTEs? Is the expectation that if I am using
>> > a
>> > function from a package, even a package that I have in Depends:, that I
>> > have to explicitly declare these imports in NAMESPACE?
>>
>> Yes.
>>
>> (Otherwise your package won't work if it's only attached and not
>> loaded. i.e. if someone does analogue::foo() only the imported
>> functions are available, not the functions in packages you depend on)
>
>
> Cheers Hadley. Thanks for the confirmation, but...
>
> ...I don't get this; what is the point of Depends? I thought it was "my
> package needs these other packages to work, i.e. be loaded". Hence it is
> user error (IMHO ;-) to do `analogue::foo()` without having the dependencies
> loaded too.

I'd say: Depends is a historical artefact from ye old days before
package namespaces. Apart from depending on a specific version of R,
you should basically never use depends.  (The one exception is, as
mentioned in R-exts, if you're writing something like latticeExtras
that doesn't make sense unless lattice is already loaded).

> This check (whilst having found some things I should have imported and
> didn't - which is a good thing!) seems to be circumventing the intention of
> having something in Depends. Is Depends going to go away?

I don't think it's going to go away anytime soon, but you should
consider it to be largely deprecated and you should avoid it wherever
possible.

>> (And really you shouldn't have any packages in depends, they should
>> all be in imports)
>
> I disagree with *any*; having say vegan loaded when one is using analogue is
> a design decision as the latter borrows heavily from and builds upon vegan.
> In general I have moved packages that didn't need to be in Depends into
> Imports; in the version I am currently doing final tweaks on before it goes
> to CRAN I have remove all but vegan from Depends.

I think that is a reasonable use case for depends. Here's the exact
text from R-exts: "Field ‘Depends’ should nowadays be used rarely,
only for packages which are intended to be put on the search path to
make their facilities available to the end user (and not to the
package itself): for example it makes sense that a user of package
latticeExtra would want the functions of package lattice made
available."

Personally I avoid even this use, requiring users of my packages to be
explicit about exactly what packages are on the search path.  You are
of course welcome to your own approach, but I think you'll find it
will become more and more difficult to maintain in time. I recommend
that you bite the bullet now.

Put another way, packages should be extremely conservative about
global side effects (and modifying the search path is such a
side-effect)

Hadley

-- 
http://had.co.nz/



More information about the R-devel mailing list