library() in .Rd Examples (Depends vs. Imports)?

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

library() in .Rd Examples (Depends vs. Imports)?

Jonathan Greenberg-4
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?

--j

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: library() in .Rd Examples (Depends vs. Imports)?

Duncan Murdoch-2
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

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel