0Pricing
R Academy · Lesson

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 builds

All lessons in this course

  1. Package Structure with usethis and devtools
  2. Documenting Functions with roxygen2
  3. Unit Testing with testthat
  4. CRAN Submission and Package Maintenance
← Back to R Academy