Basic Structure of R package
An R package begins life as a directory on your computer. This directory has a specific layout with specific files and sub-directories. The two required sub-directories are
R, which contains all of your R code files
man, which contains your documentation files.
At the top level of your package directory you will have a DESCRIPTION file and a NAMESPACE file. This represents the minimal requirements for an R package. Other files and sub-directories can be added and will discuss how and why in the sections below.
While RStudio is not required to build R packages, it contains a number of convenient features that make the development process easier and faster. That said, in order to use RStudio for package development, you must setup the environment properly. Details of how to do this can be found in Roger’s RStudio package development pre-flight check list.
Building R Packages Pre-Flight Check List
Install latest version of R
Install latest version of RStudio
Open RStudio
Install
devtoolsandusethispackage (may take a few minutes) or update packagesInstall
roxygen2packageClick on Project —> New Project —> New Directory —> R Package
Enter package name
Verify that project subdirectory name does not contain any spaces
Click “Create Project”
Delete bolierplate code and
hello.Rfile in theRdirectoryGoto the
mandirectory and delete thehello.RdfileIn File browser, click on the package name to go to the top level directory
Click “Build” tab in environment browser
Click More —> “Configure Build Tools”
Check “Generate documentation with Roxygen” –> Click the “Configure…” button
Check “Build & Reload” in the Roxygen Options -> Click OK
Click OK in Project Build Tools Options