spatstat.utils (version 2.0-0)

check.named.vector: Check Whether Object Has Required Components

Description

These functions check whether the object x has components with the required names, and does not have any unexpected components.

Usage

check.named.vector(x, nam, context = "", namopt = character(0),
                   onError = c("fatal", "null"))

check.named.list(x, nam, context = "", namopt = character(0), onError = c("fatal", "null"))

check.named.thing(x, nam, namopt = character(0), xtitle = NULL, valid = TRUE, type = "object", context = "", fatal = TRUE)

Arguments

x

The object to be checked.

nam

Vector of character strings giving the names of all the components which must be present.

namopt

Vector of character strings giving the names of components which may optionally be present.

context

Character string describing the context in which x is being checked.

xtitle

Optional character string to be used when referring to x.

valid

Logical value indicating whether x belongs to the required class of objects.

type

Character string describing the required class of objects.

onError

Character string indicating what to do if x fails the checks.

fatal

Logical value indicating what to do if x fails the checks. If fatal=TRUE (the default), an error occurs.

Value

check.named.vector returns a numeric vector or NULL.

check.named.list returns a list or NULL.

check.named.thing returns a character vector.

Details

check.named.thing checks whether x has all the required components, in the sense that names(x) includes all the names in nam, and that every entry in names(x) belongs to either nam or namopt. If all these checks are true, the result is a zero-length character vector. Otherwise, if fatal=TRUE (the default), an error occurs; otherwise the result is a character vector describing the checks which failed.

check.named.vector checks whether x is a numeric vector and check.named.list checks whether x is a list. They then call check.named.thing to check whether all the required components are present. If all these checks are true, the result is a reordered version of x in which all the compulsory entries appear first. Otherwise, if onError="fatal" (the default) an error occurs; otherwise the result is NULL.

See Also

check.1.integer

Examples

Run this code
# NOT RUN {
  z <- list(a=1, b=2, e=42)
  check.named.list(z, c("a", "b"), namopt=c("c", "d", "e"))
  check.named.thing(z, c("a", "b"), namopt=c("c", "d", "e"))
  zz <- unlist(z)
  check.named.vector(zz, c("a", "b"), namopt=c("c", "d", "e"))
  check.named.thing(z, c("b", "c"), namopt=c("d", "e"), fatal=FALSE)
# }

Run the code above in your browser using DataCamp Workspace