Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

has_attributes

Does the input have the specified attributes?


Description

Checks to see if the input has the specified attributes.

Usage

assert_has_all_attributes(x, attrs, severity = getOption("assertive.severity",
  "stop"))

assert_has_any_attributes(x, attrs, severity = getOption("assertive.severity",
  "stop"))

has_attributes(x, attrs, .xname = get_name_in_parent(x))

Arguments

x

Input to check.

attrs

Desired attributes.

severity

How severe should the consequences of the assertion be? Either "stop", "warning", "message", or "none".

.xname

Not intended to be used directly.

Value

has_attributes returns TRUE where x has the attributes specified in attrs. assert_has_terms returns nothing but throws an error if has_terms is not TRUE.

See Also

has_any_attributes for checking that an object has any attributes at all.

Examples

# has_attributes is vectorized on attrs
has_attributes(sleep, c("class", "names", "row.names", "col.names"))

# You can check for any or all of these attributes to be present.
x <- structure(c(a = 1), b = 2)
assert_has_all_attributes(x, c("names", "b"))
assert_has_any_attributes(x, c("names", "not an attribute"))

# These examples should fail.
assertive.base::dont_stop({
assert_has_all_attributes(x, c("names", "not an attribute"))
})

assertive.properties

Assertions to Check Properties of Variables

v0.0-4
GPL (>= 3)
Authors
Richard Cotton [aut, cre]
Initial release
2016-12-29

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.