check_named_list: Check that a list is named

View source: R/checks.R

check_named_listR Documentation

Check that a list is named

Description

This function checks that the top level of a list is named (ignoring empty lists if requested). If the list is not named, the function returns a helpful error message. Otherwise, the list is returned unchanged. This is particularly useful within functions that use do.call to evaluate lists of arguments.

Usage

check_named_list(arg = deparse(substitute(input)), input, ignore_empty = TRUE)

Arguments

arg

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

input

A list.

ignore_empty

A logical input which defines whether or not to ignore empty lists.

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

# This returns input unchanged:
check_named_list(input = list(), ignore_empty = TRUE)
check_named_list(input = list(a = "b"))
# This returns an error:
## Not run: 
#' check_named_list(input = list(), ignore_empty = FALSE)

## End(Not run)
# This returns an error which includes the argument name:
## Not run: 
check_named_list(arg = "x", input = list(1))

## End(Not run)


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