[Rd] library() in .Rd Examples (Depends vs. Imports)?
Duncan Murdoch
murdoch.duncan at gmail.com
Thu Oct 8 20:12:34 CEST 2015
On 08/10/2015 1:51 PM, Jonathan Greenberg wrote:
> I'm a little confused when documenting my code using Imports vs. Depends.
> If I have an example in my .Rd that uses a library that is listed under
> Imports, it doesn't work, but if it is listed under Depends, it does. What
> is the proper way to go about using examples that rely on an Imports?
> Should I just if(require(somepackage)) in the example? Or is there a more
> elegant way of doing this?
The more elegant way is to use somepackage::somefunction(...). You
should avoid using require(somepackage), because that modifies the
user's search list; they may not want you to do that.
Within your own package code you won't need the somepackage:: prefix if
you import the function in your NAMESPACE file, but help page examples
are executed in the user's context, so they can't see imports.
Duncan Murdoch
More information about the R-devel
mailing list