check_length: Check the length of an input to a parent function

View source: R/checks.R

check_lengthR Documentation

Check the length of an input to a parent function

Description

This function checks that the length of an input to a parent function is correct. If not, the function returns a helpful error message.

Usage

check_length(
  arg = deparse(substitute(input)),
  input,
  req_length,
  req_arg = deparse(substitute(req_length))
)

Arguments

arg

(optional) A character string which defines the argument of a parent function.

input

An object.

req_length

A number which defines the required length of input.

req_arg

A character which defines the name of the object which defines the required length.

Value

The function returns a helpful error message for unnamed lists (ignoring empty lists if requested) or the inputted list unchanged.

Author(s)

Edward Lavender

Examples

## Not run: 
x <- data.frame(x = 1, y = 1)
labels = 1:10
check_length(arg = "labels",
             input = labels,
             req_length = length(colnames(x)),
             req_arg = "colnames(x)"
)

## End(Not run)


edwardlavender/utils.add documentation built on Dec. 14, 2024, 8:11 a.m.