formatR (version 1.5)

usage: Show the usage of a function

Description

Print the reformatted usage of a function. The arguments of the function are searched by argsAnywhere, so the function can be either exported or non-exported in a package. S3 methods will be marked.

Usage

usage(FUN, width = getOption("width"), tidy = TRUE, output = TRUE, 
    indent.by.FUN = FALSE, fail = c("warn", "stop", "none"))

Arguments

FUN

the function name

width

the width of output

tidy

whether to reformat the usage code

output

whether to write the output to the console (via cat)

indent.by.FUN

whether to indent subsequent lines by the width of the function name (see “Details”)

fail

a character string that determines whether to generate a warning, stop, or do neither, if the width constraint is unfulfillable (default is "warn")

Value

The R code for the usage is returned as a character string (invisibly).

Details

Line breaks in the output occur between arguments. In particular, default values of arguments will not be split across lines.

When indent.by.FUN is FALSE, indentation is set by the option getOption("formatR.indent", 4L), the default value of the indent argument of tidy_source.

See Also

tidy_source

Examples

Run this code
# NOT RUN {
library(formatR)
usage(var)

usage(plot)

usage(plot.default)  # default method
usage("plot.lm")  # on the 'lm' class

usage(usage)

usage(barplot.default, width = 60)  # output lines have 60 characters or less

# indent by width of 'barplot('
usage(barplot.default, width = 60, indent.by.FUN = TRUE)

# }
# NOT RUN {
# a warning is raised because the width constraint is unfulfillable
usage(barplot.default, width = 30)
# }

Run the code above in your browser using DataCamp Workspace