Code Monkey home page Code Monkey logo

roxygen's Introduction

roxygen2

all' hileth', Hephaiste; didou d'areten te kai olbon.* --Homer, 7th century BCE

Why use roxygen2?

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

#' The length of a string (in characters).
#'
#' @param string input character vector
#' @return numeric vector giving number of characters in each element of the 
#'   character vector.  Missing string have missing length.
#' @keywords character
#' @seealso \code{\link{nchar}} which this function wraps
#' @export
#' @examples
#' str_length(letters)
#' str_length(c("i", "like", "programming", NA))
str_length <- function(string) {
  string <- check_string(string)

  nc <- nchar(string, allowNA = TRUE)
  is.na(nc) <- is.na(string)
  nc
}

When you roxygenise your package these comments will be automatically transformed to the Rd file you need to pass R CMD check:

\name{str_length}
\alias{str_length}
\title{The length of a string (in characters).}
\usage{str_length(string)}
\arguments{
  \item{string}{input character vector}
}
\description{
  The length of a string (in characters).
}
\seealso{\code{\link{nchar}} which this function wraps}
\value{numeric vector giving number of characters in each element of the
character vector.  Missing string have missing length.}
\keyword{character}
\examples{
  str_length(letters)
  str_length(c("i", "like", "programming", NA))
}

Running roxygen2

library(roxygen2)
roxygenize('<package>')

By default, roxygen2 will create files in the package man directory, although if you're worried you can override the defaults to copy the complete package to a new directory and create the files there.

Roclets

roxygen2 comes with three roclets, three tools for parsing your source code and producing files useful for documenting your package:

  • collate_roclet: allows you to add @include directives to ensure that files are loaded in the order they are needed

  • namespace_roclet: creates your NAMESPACE automatically. 95% of the time all you need to do is label functions, methods and classes that you want to export with the @export tag

  • rd_roclet: produces Rd files by inspecting both function definitions and roxygen2 comments in the source code.

By default, roxygenise will run all three, but you can choose which ones to run using the roclet parameter. It's also possible to write your own roclets - more on this in the future.

Thanks

  • Tobias Verbeke, for catching an unadorned URL.

  • Hail, Hephaistos! Grant skill and weal.

roxygen's People

Contributors

briandk avatar hadley avatar klutometis avatar mjaeugster avatar yihui avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.