check_named_vctr: Check a named vector

View source: R/check_named_vctr.R

check_named_vctrR Documentation

Check a named vector

Description

This function checks whether named lists and vectors contain invalid values (like NULL or NA), have invalid names (such as missing or empty names), ensures the number of valid names matches the number of supplied values, and confirms that valid names from the object correspond to the provided names. If any of these checks fail, the function returns the default value.

Usage

check_named_vctr(x, names, default)

Arguments

x

A named vector.

names

A character vector or list of character vectors of length one specifying the names to be matched.

default

Default value to return

Value

Either the original object, x, or the default value.

Author(s)

Ama Nyame-Mensah

Examples


# returns NULL
check_named_vctr(x = c(one = 1, two = 2, 3), 
                 names = c("one", "two", "three"),
                 default = NULL)
                 
# returns x
check_named_vctr(x = list(one = 1, two = 2, three = 3), 
                 names = list("one", "two", "three"),
                 default = NULL)  

# also returns x
check_named_vctr(x = c(baako = 1, mmienu = 2, mmiensa = 3), 
                 names = list("baako", "mmienu", "mmiensa"),
                 default = NULL)              
                 

summarytabl documentation built on Nov. 6, 2025, 5:07 p.m.