Learn R Programming

rray (version 0.0.0.9000)

vec_cast_inner: Cast to an inner type

Description

vec_cast_inner() casts x to the "inner" type of to, maintaining the size and shape of x.

vec_cast_inner_common() casts its input to a common inner type, maintaining the size and shape of each input.

Usage

vec_cast_inner(x, to)

# S3 method for default vec_cast_inner(x, to)

vec_cast_inner.logical(x, to)

vec_cast_inner.integer(x, to)

vec_cast_inner.double(x, to)

vec_cast_inner.character(x, to)

vec_cast_inner.vctrs_rray_lgl(x, to)

vec_cast_inner.vctrs_rray_dbl(x, to)

vec_cast_inner.vctrs_rray_int(x, to)

vec_cast_inner_common(..., .to = NULL)

Arguments

x

Vector to cast.

to

Object with the inner type to cast to.

...

Vectors to cast to a common inner type.

.to

If not NULL, the inner type to force all objects in ... to be cast to.

Details

vec_cast_inner() makes no guarantees that the attributes of x are retained (with the exception of the dim), only that the inner type will be the same after the cast. This function is usually called internally to force a common inner type, perform a manipulation, and then other functionality restores the attributes and container type.

As opposed to vec_cast(), the shape of x is maintained.

Examples

Run this code
# NOT RUN {
# Casting from logical to double.
# Not worrying about the fact that `to`
# is an rray.
# vec_cast_inner(TRUE, rray(1))

# Casting from a double to a logical
# Note that the rray attributes are lost.
# This is expected as the only thing
# `vec_cast_inner()` cares about is
# the internal type
# vec_cast_inner(rray(1), TRUE)

# Shape of `x` is kept
# vec_cast_inner(matrix(c(TRUE, FALSE)), rray(1))

# }

Run the code above in your browser using DataLab