Learn R Programming

rray (version 0.0.0.9000)

vec_type_container: Find the container type of a set of vectors

Description

vec_type_container() finds the container type of a single vector. vec_type_container_common() finds the common container type of multiple vectors.

Usage

vec_type_container(x)

vec_type_container_common(..., .ptype = NULL)

Arguments

x

Vector to compute the container type for.

...

Vectors to compute the common container type for.

.ptype

If not NULL, overrides the common container type of ....

Details

The container type is a 0-size, 0-shape prototype that represents the "container" of x. A container is generally an S3 class that can hold multiple different "inner" types. For example, an rray is a container that can hold integers, logicals, or doubles as inner types.

For base R objects, this returns logical().

For more complex types, a method should be written that returns an empty version of the input with no shape or size. If that complex type can have multiple inner types, pick one to return consistently for all inner type variations, as there should be no reliance on the inner type when inspecting the container type.

The common container type is useful alongside vec_cast_container(). For example, rray_greater() uses vec_type_container_common() to determine the common container for the output, and then uses vec_cast_container() to restore the logical result of the comparison to either an rray or an array, depending on the container type.

Critically, the container type is independent of the inner type of a vector. This means that while vec_type_common(character(), numeric()) is an error, vec_type_container_common(character(), numeric()) returns logical() because they are both base R containers.

Examples

Run this code
# NOT RUN {
# The container of base R atomics is just logical()
# vec_type_container(1)

# The container of an rray is an empty logical rray
# vec_type_container(rray(1))

# Find the common container of multiple types
# (the rray type is more complex here, and becomes the common container)
# vec_type_container_common(1, TRUE, rray(1L))

# Not an error!
# vec_type_container_common(character(), logical())

# }

Run the code above in your browser using DataLab