From murdoch.duncan at gmail.com  Thu Oct  8 20:12:34 2015
From: murdoch.duncan at gmail.com (Duncan Murdoch)
Date: Thu, 8 Oct 2015 14:12:34 -0400
Subject: [Rd] library() in .Rd Examples (Depends vs. Imports)?
In-Reply-To: <CABG0rfvubYw7HVFA_AQW4wGr4NvXY_1dZv7JDUP7TmULuE94eg@mail.gmail.com>
References: <CABG0rfvubYw7HVFA_AQW4wGr4NvXY_1dZv7JDUP7TmULuE94eg@mail.gmail.com>
Message-ID: <5616B212.3060301@gmail.com>

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



[Rd] library() in .Rd Examples (Depends vs. Imports)?
Duncan Murdoch