9 Filestructure
9.1 Introduction
In this chapter we describe the anatomy of a package: the types of files and their organization into various directories.
9.2 Scenarios
The following diagram depicts three possible (hypothetical) filestructures for a package. From a minimal version, to the default contents created by "devtools"
, to a more sophisticated structure.

Figure 9.1: Three possible filestructures for a package
9.3 Minimal Package
The first option is what it’s considered to be a minimal package.

Figure 9.2: Filestructure of a minimal package
Every package must have at least the following four components:
DESCRIPTION
fileNAMESPACE
fileR/
directoryman/
directory
Without any of these four elements, you won’t be able to create a valid R package.
9.4 Default devtools setting
The second option corresponds to the default structure generated by RStudio when you use an RStudio project—via the package "devtools"
.

Figure 9.3: Default filestructure created by devtools
In addition to the files and directories of the previous option, now there are two more files:
- A text file
.Rproj
(i.e. an RStudio project file) - A text file
.Rbuildignore
file
9.5 Our working example
The third option is the actual structure for our working example.

Figure 9.4: Filestructure of the working example
Starting with a default structure, we can add more elements like a README.md
files, and directories for tests/
and vignettes/
. The extra directory inst/
is generated in the building process.
You can add more files and directories to make a more complex and robust package. However, to keep a focused scope on this book we will concentrate on the above structure.
Make a donation
If you find this resource useful, please consider making a one-time donation in any amount. Your support really matters.