Monday 15 August 2011

How do I prevent "r 'library' or 'require' calls not declared" warnings when developing a package? -


I am developing a package that depends on the package foo , and in my package code Call the exported code from foo I have included the package name in the NAMESPACE in the Import (Af) declaration, and import Under: line description file However, I get the following warning when RCM check :

  r 'library 'Or' require 'call can not be declared Yes: 'foo'   

What am I missing?

There is a similar question, but it does not discuss this specific warning.

() or library (& lt ); Pkg & gt;) . The error message is a little confusing - it's telling you that you have placed the requirement or library in your code, but in reality (properly) those calls are not declared In your DESCRIPTION file.

If you intend to use code from those packages in your package, you should call this library / call ; Rather, you need to declare them properly (and how you're using them) in your DESCRIPTION file.

Mostly, you want to import 'package and some, or all, for export functions / symbols available for your package. You can add such packages to your DESCRIPTION file in the Import: field - e.g.

  Import: & lt; Pkg & gt;   

And likewise, announce that you want to write all in the NAMESPACE file using the symbols exported from that package ,

Import

By doing this, & lt; Pkg & gt; All functions in the namespace are automatically provided and therefore it is not necessary for requirement anywhere in your code.

In the context of a package, the main use of is that which you want to make only conditionally, for example, suppose that you write the function that Handles a very specific conspiracy arrangement, which requires foo , but foo is not required in your package otherwise, if you include code Want to do the conditional package foo Depending on it, you can write something in this form:

  (if required ("foo")) {#do stuff}   

And then you can include foo under DESCRIPTION instead of sequence: import: . Another example is a package that is not required by the users of your package.

In short: If you are importing packages to use only those packages exported to the namespace of that package, then you can send your package to Library or is not needed anywhere in the code.

EDIT: In newer versions of R, the RCM check if you use , , warns it, And instead you suggest that you use requireNamespace . In that case, you can follow the pattern:

  ## Use the 'bar' function from the package 'Foo' (if required requires "name" ("foo", quietly = TRUE)) {foo :: Bar ()}    

No comments:

Post a Comment