
Rbuildignore lists files that should not be included when building the R package To start the development of a new R package, we attach the devtools package and call the create_package() function that initializes the components of the package. To develop the package, we use the devtools package (which also uses other packages such as usethis for package development). Here we provide a small example on how to create an R package called mypackage that has a function called fnAreaCircle() that calculates the area of a circle given its radius. Inspect the source of the ggplot2 package in GitHub:
devtools::install(): uses R CMD INSTALL to install a package. devtools::check(): builds and checks a package for any ERRORs, WARNINGs, or NOTEs. usethis::use_vignette(): creates a new vignette in vignettes/. devtools::document(): creates documentation files in man/ and the NAMESPACE file from roxygen2 code (it is a wrapper of roxygen2::roxygenize()). usethis::use_data(): saves an object in the R session as a dataset in the package.
usethis::use_package(): adds a package dependency to the DESCRIPTION file. devtools::load_all(): loads all functions in a package like when a package is installed and attached with library(). usethis::create_package(): creates the file structure for a new package.
The following functions are key for package development. The roxygen2 package allows us to easily create documentation for the functions and data contained in the packages. To create an R package, we can use the devtools and usethis packages which include a variety of tools aimed at package development. binary: single compressed file optimized for a specific OS.
source: directory with subdirectories as above. The contents of a package can be stored as Other common parts include subdirectories data, tests and vignettes. NAMESPACE file that specifies exported functions that can be accessed by the users and imported functions from other packages. DESCRIPTION file with metadata for the package such as the name, version number and author.
Subdirectory man that contains the documentation. Subdirectory R that contains R files with functions. The minimal requirements for an R package are the following: R packages are directories with subdirectories containing R functions, data, documentation and other information. R packages can be shared for reuse by others in several ways.įor example, they can be contributed to the Comprehensive R Archive Network (CRAN), put in GitHub, or distributed privately using files shares. R packages provide a way to distribute R code, data and documentation.