has_only_names: Returns TRUE if data.frame or list has only the specified...

View source: R/utils.R

has_only_namesR Documentation

Returns TRUE if data.frame or list has only the specified names

Description

This function checks parent frame environment for a specific set of names; if more columns are present than those specified, an error is raised.

Usage

has_only_names(...)

Arguments

...

An arbitrary amount of quoted names to check for. Character vectors of names are accepted too.

Details

This is meant to be used with ‘assertr'’s 'verify' function to check for the existence of specific column names in a 'data.frame' that is piped to 'verify'. It can also work on a non-'data.frame' list.

Value

TRUE is all names exist, FALSE if not

See Also

Other Name verification: has_all_names()

Examples


# The last two columns names are switched in order, but all column names are
# present, so it passes.
verify(
  mtcars,
  has_only_names(c(
    "mpg", "cyl", "disp", "hp", "drat", "wt", "qsec", "vs", "am",
    "carb", "gear"
  ))
)

# More than one set of character strings can be provided.
verify(
  mtcars,
  has_only_names(
    c("mpg", "cyl", "disp", "hp", "drat", "wt", "qsec", "vs", "am"),
    c("carb", "gear")
  )
)

## Not run: 
# The some columns are missing, so it fails.
verify(mtcars, has_only_names("mpg"))

## End(Not run)

assertr documentation built on Nov. 13, 2026, 1:12 a.m.