check_names: Check the names of an object contain required names

View source: R/checks.R

check_namesR Documentation

Check the names of an object contain required names

Description

This function checks whether required names are contained within an object. If the object does not contain any/all required names (the precise criteria is controlled by the user), the function returns a helpful error message.

Usage

check_names(
  arg = deparse(substitute(input)),
  input,
  req,
  extract_names = names,
  type = any
)

Arguments

arg

A character string which defines the argument of the parent function.

input

An object for which the names need to be checked.

req

A character vector of required names.

extract_names

A function which is used to extract names from input, such as names or colnames.

type

A function which defines the failure criteria. For example, if type = all, the function will return an error unless all the names in req are contained within input. This is the default. If type = any, the function will return an error only if none of the names in req are contained within input.

Value

If the input fails the check, the function returns a helpful error message. Otherwise, nothing is returned.

Author(s)

Edward Lavender

Examples

## Not run: 
check_names(input = list(x = 1, y = 1),
            req = c("a", "b", "c"),
            extract_names = names,
            type = all)
check_names(input = data.frame(b = 1, a = 1),
            req = c("x", "y"),
            extract_names = colnames,
            type = any)

## End(Not run)


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