Learn R Programming

rray (version 0.0.0.9000)

vec_cast_container: Cast to a container type

Description

vec_cast_container() casts x to the "container" type of to. This should make the following assumptions:

  • x has the correct shape.

  • x has the correct internal type.

vec_cast_container_common() casts multiple vectors to a common container type.

Usage

vec_cast_container(x, to)

# S3 method for default vec_cast_container(x, to)

vec_cast_container.logical(x, to)

vec_cast_container.double(x, to)

vec_cast_container.integer(x, to)

vec_cast_container.vctrs_rray(x, to)

vec_cast_container_common(..., .to = NULL)

Arguments

x

Vector to cast.

to

Container type to cast to.

...

Vectors to cast to a common container type.

.to

If not NULL, overrides the common container type to cast ... to.

Details

vec_cast_container() is useful for restoring input that has been modified in some way back to its original container type without altering the internal type or shape of the modified input. For example, the > method for rrays takes two inputs, finds the common container type between them and returns a logical vector wrapped in that container type.

When casting between base R types, this simply returns x.

Examples

Run this code
# NOT RUN {
# Upcasting to an rray. Still a logical
# vec_cast_container(TRUE, rray(1))

# Downcasting to a double, no longer an rray
# (the "container" here is just a base R object)
# vec_cast_container(rray(1), TRUE)

# Shape of `x` is kept
# vec_cast_container(matrix(1:5), rray(1))

# Dim names of `x` are kept
x <- rray(1:2, dim_names = list(c("r1", "r2")))
# vec_cast_container(x, 1)

# }

Run the code above in your browser using DataLab