Overview: how to write your first R package

less than 1 minute read

Published:

This blog post provides a brief overview of the key steps involved in creating, documenting, and publishing your first R package.

$\textbf{Operating system:}$ Windows, $\textbf{R version:}$ 4.2.3.

Creating R package, writing R functions, and documentation.

Packages you may need:

library(devtools) 
library(usethis)

Steps:

  • New Project –> New Directory –> R package using devtools –> Directory Name –> Create Project.
  • Create .R file using
    usethis::use_r("your_function_name") 
    
  • Create .Rd using
    • Alt+Ctrl+Shift+R, or
    • Code –> Insert Roxygen Skeleton
  • Create help file using
    • Ctrl+Shift+D –> Load All, or
    • Build –> Document –> Load All
  • Or use devtools:
    • Load All
      devtools::load_all(".")
      
    • document
      devtools::document()
      

Folders:

  • R folder: contains R function. All files end with .R
  • man folder: contains help files. All files end with .Rd

Package pdf manual:

devtools::build_manual()

Resources: