usage: Return the Usage of a Function From Within the Function

View source: R/man.R

usageR Documentation

Return the Usage of a Function From Within the Function

Description

Get a usage template for a function from within the function. If you encounter misguided usage, you can display the template.

Usage

usage(n = -1, usage = FALSE)

Arguments

n

A negative integer giving the number of from to frames/environments to go back (passed as which to sys.call). Set to -2 if you want to encapsulate the call to usage into a function (like print or assign) within the function you want to obtain the usage for. Use the <- assignment operator with the default, see examples below.

usage

Give this functions usage (as a usage example ...) and exit?

Value

A character string giving the Usage as help would do.

Examples

# usage with assignment operator:
foo <- function(x) {
    u <- usage()
    message("Usage is: ", u)
}
foo()

# usage without assignment operator:
bar <- function(x) {
    message(usage(n = -2))
}
bar()

document documentation built on July 9, 2023, 5:22 p.m.