In-Line Documentation for R

Generate your Rd documentation, 'NAMESPACE' file, and collation field using specially formatted comments. Writing documentation in-line with code makes it easier to keep your documentation up-to-date as your requirements change. 'roxygen2' is inspired by the 'Doxygen' system for C++.


roxygen2 roxygen2 website

CRAN status R-CMD-check Codecov test coverage

The premise of roxygen2 is simple: describe your functions in comments next to their definitions and roxygen2 will process your source code and comments to automatically generate .Rd files in man/, NAMESPACE, and, if needed, the Collate field in DESCRIPTION.

Installation

# Install roxygen2 from CRAN
install.packages("roxygen2")

# Or the development version from GitHub:
# install.packages("pak")
pak::pak("r-lib/roxygen2")

Usage

The premise of roxygen2 is simple: describe your functions in comments next to their definitions and roxygen2 will process your source code and comments to produce Rd files in the man/ directory. Here's a simple example from the stringr package:

#' The length of a string
#'
#' Technically this returns the number of "code points", in a string. One
#' code point usually corresponds to one character, but not always. For example,
#' an u with a umlaut might be represented as a single character or as the
#' combination a u and an umlaut.
#'
#' @inheritParams str_detect
#' @return A numeric vector giving number of characters (code points) in each
#'    element of the character vector. Missing string have missing length.
#' @seealso [stringi::stri_length()] which this function wraps.
#' @export
#' @examples
#' str_length(letters)
#' str_length(NA)
#' str_length(factor("abc"))
#' str_length(c("i", "like", "programming", NA))
str_length <- function(string) {
}

When you roxygenise() (or devtools::document()) your package these comments will be automatically transformed to the .Rd that R uses to generate the documentation you see when you type ?str_length.

Learn more

To get started, first read vignette("roxygen2"). Then read more about the specific package component that you want to generate:

  • vignette("rd-functions") describes how to document your functions with roxygen2.

  • vignette("rd-S3"), vignette("rd-S4"), vignette("rd-R6"), and vignette("rd-S7") discuss documenting the various OOP systems.

  • vignette("rd-datasets") and vignette("rd-packages") cover documenting datasets and the package itself.

  • vignette("rd-formatting") gives the details of roxygen2's rmarkdown support.

  • vignette("reuse") demonstrates the tools available to reuse documentation in multiple places.

  • vignette("namespace") describes how to generate a NAMESPACE file, how namespacing works in R, and how you can use roxygen2 to be specific about what your package needs and supplies.

  • For the Collate field in the DESCRIPTION, see ?update_collate().

Reference manual

It appears you don't have a PDF plugin for this browser. You can click here to download the reference manual.

install.packages("roxygen2")

8.1.1 by Hadley Wickham, 8 days ago


https://roxygen2.r-lib.org/, https://github.com/r-lib/roxygen2


Report a bug at https://github.com/r-lib/roxygen2/issues


Browse source code at https://github.com/cran/roxygen2


Authors: Hadley Wickham [aut, cre, cph] (ORCID: , Peter Danenberg [aut, cph] , Gábor Csárdi [aut] , Manuel Eugster [aut, cph] , Posit Software , PBC [cph, fnd] (ROR: <https://ror.org/03wc8by49>)


Documentation:   PDF Manual  


MIT + file LICENSE license


Imports brew, cli, commonmark, desc, knitr, lifecycle, methods, pkgload, R6, rdtools, rlang, stats, utils, withr, xml2

Suggests covr, R.methodsS3, S7, R.oo, rmarkdown, testthat, yaml

Linking to cpp11


Imported by DWaveNARDL, DataPackageR, RadEro, Rd2roxygen, TKCat, admiraldev, anyflights, aoos, assertHE, attachment, checkhelper, commons, devtools, docstring, doctest, document, drugsens, exampletestr, fusen, goodpractice, interfacer, languageserver, leprechaun, link2GI, maestro, makepipe, pkgstats, plumber2, populationPDXdesign, rUM, redland, releaser, roclang, roxy.shinylive, roxyglobals, roxylint, roxyreqs, roxytest, roxytypes, srr.

Depended on by miscFuncs, roxut.

Suggested by AFR, APTIcalc, ASMbook, AgroR, AirMonitor, AlleloBin, BAS, BFI, BayesRep, BayesRepDesign, BayesianLaterality, BayesianTools, Bernadette, CAOP.RAA.2024, CohortSurvival, ConfMatrix, CrossClustering, D4TAlink.light, DSAIDE, DSAIRM, DepthProc, DrImpute, EDIutils, EFSATools, EstimateBreed, GBOP2, GRCFE, GoldenVizR, HDMAADMM, HiClimR, HyMETT, IRkernel, JSmediation, LLMAgentR, LLMR, LWFBrook90R, MDDC, MDP2, MFRCD, MIDASim, MLBC, MNormTest, MSMU, MacBehaviour, MazamaCoreUtils, MazamaLocationUtils, MazamaRollUtils, MazamaSpatialPlots, MazamaTimeSeries, NACHO, OBIC, OneTwoSamples, Open.Visualization.Academy, OpenMx, POMADE, PPforest, PPtreeExt, PRDA, Path.Analysis, PosteriorBootstrap, PracTools, ProcMod, QuadratiK, RAGFlowChainR, RAQSAPI, RCzechia, REDCapCAST, REDCapExporter, REXoplanets, RItools, RMSTpowerBoost, RQEntangle, RcppBessel, RcppProgress, RealVAMS, ReplicationSuccess, Require, Rpadrino, Rtwalk, RulesTools, SCDB, SIAtools, SMMT, SQLFormatteR, SSP, SampleSizeCalculator, SampleSizeDiagnostics, SpaDES.core, SunCalcMeeus, SurfaceTortoise, SurrogateRank, TAD, TDCM, Tejapi, TemporalHazard, TextAnalysisR, Visualize.CRAN.Downloads, WCRBayesDesign, WData, WaveST, WufooR, ZINAR1, aRxiv, acepack, activatr, additive, admiralonco, admiralophtha, admiralvaccine, alfr, altadata, alternativeROC, amorem, anomalize, apisensr, audubon, autoshiny, autoslider.trade, autotest, aweek, baizer, bark, baseline, bayesian, bfpwr, bigbang, bioC.logs, biostats101, birdie, bit, blockr.core, bluertopo, boot.heterogeneity, bootGOF, box, brar, broadcast, broman, bsynth, btw, buildr, bunchr, bursa, campsis, campsismod, campsisnca, camsRad, capr, caretEnsemble, cargo, carwatch, catalog, causalBatch, causens, censable, cgam, chatLLM, chromer, ciCalibrate, circumplex, civis, classbound, climenu, clugenr, clustermole, clustermq, cmna, cmpp, cnd, codebook, collatz, condTruncMVN, configulaR, contrastable, cookies, covid19.analytics, cp1919, cppally, crul, ctf, datacutr, dcm2, debkeepr, deident, denguedatahub, denvax, descsuppR, designit, devkit, dispositionEffect, distilleR, divseg, dotCall64, dr4pl, dynr, edgarWebR, eiExpand, emBALVI, emayili, epiflows, epigraphdb, episensr, epitrix, eppoFindeR, exoplanetdata, expstudy, ezcox, factory, fakemake, faux, ferrn, ffp, fgeo.tool, filters.trade, fitzRoy, flexstanr, flippant, forecastHybrid, fscache, funcml, gMOIP, geometa, geomtextpath, geonapi, geonetwork, geonode4R, geosapi, geozoo, gert, getCRUCLdata, ggDoE, ggalignment, ggenealogy, ggplayfair, ggplot2, ggragged, ggsegmentedtotalbar, ggtime, gibasa, gimap, gipsDA, golem, googleAuthR, gqlr, hardhat, hdcuremodels, heddlr, hopit, howManyImputations, html2pdfR, hyd1d, hydflood, ibb, ifaTools, iheatmapr, immunarch, imt, imuGAP, inlcolor, insane, intergraph, ipmr, islasso, isobxr, izmir, jubilee, knitrBootstrap, konfound, labelmachine, latrend, latticeDensity, lcc, ldamatch, ldhmm, learnrbook, leontief, lineup, lineup2, litterfitter, lmQCM, logger, lulab.utils, mapsRinteractive, marp, mase, matrixNormal, maxRgain, mbmixture, mcmcsae, measr, mectx, memofunc, metaconfoundr, metagam, metan, metasurvey, metawho, mgarchBEKK, micompr, mikropml, min2HalfFFD, miniCRAN, missknn, mizer, mmconvert, monad, mongolstats, morpheus, mpmaggregate, msigdbr, msmtools, mtscr, mulSEM, multibreakeR, multimolang, multipanelfigure, multiscape, mwcsr, naaccr, nascaR.data, nat.utils, negenes, net4pg, neuroSCC, neuroim2, new.dist, nhanesdata, nima, nlmeU, noisyr, nparACT, nprcgenekeepr, nscancor, nsprcomp, nzffdr, oRaklE, ontophylo, openrouteservice, oppr, optimParallel, options, optmatch, packager, pacta.loanbook, paleobioDB, paramix, penetrance, pestr, pguIMP, pharmaverseadam, pharmaverseraw, pharmaversesdtm, phonics, photobiology, pkgKitten, pkgcheck, pkgmatch, pkgmd, poLCAParallel, pointcoral, poorman, popEpi, ppRep, ppmf, precommit, prioriactions, prioritizrdata, probcal, projections, psycCleaning, public.ctn0094data, pwrRasch, pye, qtl2, qtl2convert, qtl2ggplot, qtlcharts, questionr, r2dii.analysis, r3PG, rIACI, rYWAASB, rYoutheria, ragtop, rappdirs, raptr, rbgm, rcrossref, rddapp, rdtLite, rdwd, recexcavAAR, regport, rex, richCluster, risk.assessr, rlibkriging, rmdd, roadoi, robotoolbox, robustmatrix, rpf, rsdmx, rsei, rstanarm, rstantools, sarsop, sched, scholar, scilintr, scriptexec, sdmvspecies, seqmon, sgsR, shapr, sherlock, shinypayload, sigminer, simTool, simcross, sinew, siteymlgen, smurf, sotkanet, spdynmod, spexvb, sqlq, ssel, stRoke, statnet.common, stencilaschema, styler, survalis, surveySimR, surveyvoi, sybilion, symSEM, taxa, tcpl, tectonicr, tergo, test.assessr, testex, testthis, tidyHeatmap, tidyILD, tidymedia, tinycodet, tinyscholar, tinyshinyserver, tmt, turkeyelections, tvrmst, twotrials, unstruwwel, unusualprofile, ura, urlshorteneR, usethis, validateIt, valmetrics, vcr, vdiffr, villager, visPedigree, wdpar, webdav, webmap, wikkitidy, worrms, wrswoR, xoi, ymlthis, zzlite.


See at CRAN