R Tutorial: Description and Namespace files

Learn what goes in a package's DESCRIPTION file (metadata, version, license, author info) and NAMESPACE file (which functions to import and export). The DESCRIPTION file uses Authors@R with role codes like AUT and CTB, while NAMESPACE is auto-generated through documentation tools.
Chapters
Now you've seen the basic structure of a package and know what to do with your R functions. Let's take a look at two important aspects of your package. The description and namespace. The description file contains basic information about the package, including its authors and maintainer, its dependencies and the license. Let's take a look at an example description file. Now, the basic package metadata includes the package name that you chose when you created the package, as well as a one line title for your package and a short description. This is the information people typically use to judge the content of your package when searching for new packages. So keep it relevant and descriptive and make sure you update it. If you change the package, the version field tells us which version of the package this is. When you start making changes to your package, you should remember to increment the version number. This will allow you and others to keep track of which version of the package they are working with. Then we have the license. This defines how other people can use the code in your package. The authors at R field is where you list the package authors as R code. The R function person helps us to keep this in the right format. You need to give the first name, last name, email and role. The role is an abbreviation and there are many, many possibilities you could use. But most common for R packages are C, R, E for the package maintainer, AUT for an author, CTB for contributors, and CPH for the package copyright holder. This is often used when a company owns a copyright on a package. People can have multiple roles. You just supply them as a vector like in the example here. You can also have multiple people. You simply need to provide a vector of person calls, one for each person. The last entries of note are the Depends and Imports fields. These ensure that any other package your package needs is installed and is available to use before someone tries to run the code. You'll be looking at the differences between Depends and Imports later in this course, but for now you can see that the minimum version of R is listed in the Depends field and other package dependencies are listed in the Imports field. The namespace file allows you to control two very important things. Firstly, which functions from other packages you need access to to run the code in our package? Secondly, which functions from your package you want to make available to people using it. You will come back to both of these ideas later, but all you need to know now is that you don't need to edit this file. You will manage it with all of your other documentation. For now, let's just take a quick look at what a complete namespace might look like. This file always contains a reminder to us not to edit it, but otherwise you can see that in this package you are importing or making available to your package the functions from dplyr. From your package you are exporting or making available to the package users nacounter now you have seen these two important files. It's your turn to try creating a description file for your package.
More from Richie

#359 My Best Friend is AI with Valerie Tiberius, Professor of Philosophy at University of Minnesota

How AI Agents Will Work While You Sleep | Ruslan Salakhutdinov, Professor at Carnegie Mellon

#358 How AI Agents Will Work While You Sleep | Ruslan Salakhutdinov, Professor at Carnegie Mellon







