Learn R Programming

gtfsio (version 1.1.1)

assert_vector: Assert that an input is a vector/list with desired properties

Description

Assert that an input is a vector/list with desired properties

Usage

assert_vector(
  x,
  class,
  len = NULL,
  null_ok = FALSE,
  var_name = NULL,
  subset_of = NULL,
  named = FALSE,
  n_call = -1L
)

assert_list(x, len = NULL, null_ok = FALSE, named = FALSE)

assert_class(x, class, n_call = -1)

Value

TRUE if the check is successful. Throws an error describing the issue with the input otherwise.

Arguments

x

A vector/list. The input to be analysed.

class

A string. The class that this input should inherit from.

len

An integer. The length of the vector. If NULL, length is not checked.

null_ok

A logical. Whether the input could also be NULL.

var_name

A string. The name of the variable in the informative message. If NULL, the name is guessed from the function call.

subset_of

A character vector. If x is a character vector, specifies which values it can take. If NULL, values are not checked.

named

A logical. Whether the input should be a named vector/list. If FALSE this check is not enforced (i.e. the input object can be named even if named is FALSE).

n_call

A negative integer. The number of frames to go back to find the call to associate the error generated by the function with. Defaults to the parent frame (-1). This argument is only relevant to other assertion functions that build on top of this one.