Package Structure with usethis and devtools
Scaffold a package directory, DESCRIPTION, and NAMESPACE with usethis helpers.
Why Build an R Package?
An R package is the standard way to share reusable code, data, and documentation. Even if you never publish to CRAN, packaging your code enforces good practices: documented functions, unit tests, and a clear namespace. devtools and usethis make the process straightforward.
Creating a Package Skeleton
usethis::create_package('~/mypackage') creates a directory with all required files: DESCRIPTION, NAMESPACE, and an R/ directory. It opens the new project in RStudio automatically.
# library(usethis)
# library(devtools)
#
# usethis::create_package('~/mypackage')
#
# Creates:
# mypackage/
# DESCRIPTION <- package metadata
# NAMESPACE <- exported symbols (auto-managed by roxygen2)
# R/ <- your R source files
# .Rbuildignore <- files to exclude from package buildsAll lessons in this course
- Package Structure with usethis and devtools
- Documenting Functions with roxygen2
- Unit Testing with testthat
- CRAN Submission and Package Maintenance