Learn/R Programming/Advanced R

Writing R Packages

Topic: Packages

Advertisement

Introduction

Creating R packages shares code with others. Roxygen2 documents functions automatically.

Package Structure

mypackage/
├── DESCRIPTION
├── NAMESPACE
├── R/
│   └── functions.R
├── man/
└── tests/

DESCRIPTION File

Package: mypackage
Title: My Package
Version: 0.1.0
Author: Your Name
Description: A package description.
License: MIT
Imports: 
    ggplot2

Documentation

#' Title
#'
#' @param x Description
#' @return Description
#' @examples
#' example()
#' @export
my_function <- function(x) {
  x + 1
}

Build & Install

library(devtools)
build()
install()
check()

Summary

Packages organize and share code. Use roxygen2 for documentation.

Advertisement

Advertisement

Need More Practice?

Get personalized R programming help from ChatWhole's AI-powered platform.

Get Expert Help →