Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Upcoming NAMESPACE, Depends, Imports changes for 2.14.0 (some definitions/use please)

If you are a package author, you are hopefully well aware of upcoming changes in package structure when we move to 2.14 in about a week. One of the changes is that all packages will require a NAMESPACE, and one will be generated for you in the event you do not make one (the R equivalent of your Miranda rights in the US). So being good citizen I was trying to figure this out. Here is the section from R-exts:

1.6.5 Summary – converting an existing package

To summarize, converting an existing package to use a namespace involves several simple steps:

Identify the public definitions and place them in export directives. Identify S3-style method definitions and write corresponding S3method declarations. Identify dependencies and replace any require calls by import directives (and make appropriate changes in the Depends and Imports fields of the DESCRIPTION file). Replace .First.lib functions with .onLoad functions or useDynLib directives.

To ensure I do the right thing here, can someone give a short clear definition/answer (am I breaking a rule by having several small but related questions together?). All answers should take 2.14 into account, please:

  1. A definition of NAMESPACE as used by R
  2. Is there a way to generate a NAMESPACE prior to build and check, or do we b/c once and then edit the NAMESPACE created automatically?
  3. The difference between "Depends:" and "Imports:" in the DESCRIPTION file. In particular, why would a I put a package in "Depends:" instead of the "Imports:" or vice versa?
  4. It sounds like "require" is no longer to be used, though it doesn't say that. Is this the correct interpretation?

Thanks!

like image 204
Bryan Hanson Avatar asked Oct 24 '11 18:10

Bryan Hanson


2 Answers

I've written a little on this topic at https://github.com/hadley/devtools/wiki/Namespaces.

To answer your questions:

  1. See Dirk's answer.
  2. Use roxygen2
  3. Now that every package has a namespace there is little reason to use Depends.
  4. require should only be used to load suggested packages
like image 71
hadley Avatar answered Dec 06 '22 18:12

hadley


CRAN packages have had NAMESPACEs since almost time immortal. Just pick a few of your favorite CRAN packages and look at their NAMESPACE files.

It can be as easy as this one-liner (plus comment) taken from snow:

# Export all names unless they start with a dot
exportPattern("^[^.]")

The run R CMD check as usual, and you should be fine in most circumstances.

like image 43
Dirk Eddelbuettel Avatar answered Dec 06 '22 18:12

Dirk Eddelbuettel