Jonathan Greenberg
2015-Oct-08 17:51 UTC
[Rd] library() in .Rd Examples (Depends vs. Imports)?
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]]
Duncan Murdoch
2015-Oct-08 18:12 UTC
[Rd] library() in .Rd Examples (Depends vs. Imports)?
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
Maybe Matching Threads
- Problem understanding behaviour of versionCheck for loadNamespace (and when versions for Imports packages are checked)
- Pb with package::foo(x) <- value
- symlink noop error
- Problem understanding behaviour of versionCheck for loadNamespace (and when versions for Imports packages are checked)
- Error: C stack usage is too close to the limit when using list.files()