Skip to contents

Convert an AnvlArray to a bare R vector. The array's shape is discarded; the result is always a flat vector. Each method requires a compatible dtype:

Use as_array() to obtain an R array that preserves the shape, or nv_convert() to change the dtype of an AnvlArray before coercing.

Usage

# S3 method for class 'AnvlArray'
as.double(x, ...)

# S3 method for class 'AnvlArray'
as.integer(x, ...)

# S3 method for class 'AnvlArray'
as.logical(x, ...)

# S3 method for class 'AnvlArray'
as.vector(x, mode = "any")

Arguments

x

(AnvlArray)
Array to coerce.

...

Unused.

mode

(character(1))
For as.vector() only. See base::as.vector(). Defaults to "any", meaning the natural R type for the array's dtype.

Value

An R vector of the corresponding type (double, integer, or logical).

Examples

x <- nv_array(c(1.5, 2.5, 3.5, 4.5), shape = c(2L, 2L))
as.numeric(x)
#> [1] 1.5 2.5 3.5 4.5
as.integer(nv_array(1:6, shape = c(2L, 3L)))
#> [1] 1 2 3 4 5 6
as.logical(nv_array(c(TRUE, FALSE), dtype = "bool"))
#> [1]  TRUE FALSE
as.vector(x)
#> [1] 1.5 2.5 3.5 4.5