assert_data_frame: Check if an argument is vector of type data frame

assert_data_frameR Documentation

Check if an argument is vector of type data frame

Description

Check if an argument is vector of type data frame.

Usage

assert_data_frame(
  x,
  types = character(0L),
  any.missing = TRUE,
  all.missing = TRUE,
  min.rows = NULL,
  max.rows = NULL,
  min.cols = NULL,
  max.cols = NULL,
  nrows = NULL,
  ncols = NULL,
  row.names = NULL,
  col.names = NULL,
  null.ok = FALSE,
  .var.name = checkmate::vname(x),
  comment = NULL,
  add = NULL
)

Arguments

x

[any]
Object to check.

types

[character]
Character vector of class names. Each list element must inherit from at least one of the provided types. The types “logical”, “integer”, “integerish”, “double”, “numeric”, “complex”, “character”, “factor”, “atomic”, “vector” “atomicvector”, “array”, “matrix”, “list”, “function”, “environment” and “null” are supported. For other types inherits is used as a fallback to check x's inheritance. Defaults to character(0) (no check).

any.missing

[logical(1)]
Are vectors with missing values allowed? Default is TRUE.

all.missing

[logical(1)]
Are vectors with no non-missing values allowed? Default is TRUE. Note that empty vectors do not have non-missing values.

min.rows

[integer(1)]
Minimum number of rows.

max.rows

[integer(1)]
Maximum number of rows.

min.cols

[integer(1)]
Minimum number of columns.

max.cols

[integer(1)]
Maximum number of columns.

nrows

[integer(1)]
Exact number of rows.

ncols

[integer(1)]
Exact number of columns.

row.names

[character(1)]
Check for row names. Default is “NULL” (no check). See checkmate::check_named for possible values. Note that you can use checkmate::check_subset to check for a specific set of names.

col.names

[character(1)]
Check for column names. Default is “NULL” (no check). See checkmate::check_named for possible values. Note that you can use checkmate::check_subset to test for a specific set of names.

null.ok

[logical(1)]
If set to TRUE, x may also be NULL. In this case only a type check of x is performed, all additional checks are disabled.

.var.name

[character(1)]
Name of the checked object to print in error messages. Defaults to the heuristic implemented in vname.

comment

[character(1)]
Extra information to be appended to the standard error message in assertions.

add

[AssertCollection]
Collection to store assertions. See AssertCollection.

Details

The assertions are based on checkmate::check_data_frame. NVIcheckmate::assert_data_frame differs from checkmate::assert_data_frame in including the argument comment. The help is updated to reflect the changes.

This function does not distinguish between NA, NA_integer_, NA_real_, NA_complex_ NA_character_ and NaN.

Value

Depending on the function prefix:
If the check is successful, the function assert_Integer return x invisibly, whereas check_Integer return TRUE.
If the check is not successful, assert_Integer throws an error message and check_Integer returns a string with the error message.

If the check is successful, the function assert_data_frame return x invisibly.
If the check is not successful, assert_data_frame throws an error message.


NorwegianVeterinaryInstitute/NVIcheckmate documentation built on Dec. 14, 2024, 10:43 p.m.