Skip to contents

Convert an AnvlArray to a flat R vector, discarding the array's shape. Each method requires a compatible dtype:

  • as.double() / as.numeric(): float or (signed/unsigned) integer dtypes.

  • as.integer(): signed or unsigned integer dtypes.

  • bit64::as.integer64(): signed or unsigned integer dtypes. This is how to read i64, ui64 and ui32 values that an R integer cannot hold. It is lossless for i64 and ui32, but bit64::integer64 is itself signed, so a ui64 value >= 2^63 wraps to a negative one (exactly 2^63 becomes NA); that is warned about, and check = "err" makes it an error.

  • as.logical(): bool.

  • as.vector(): any dtype; the R type is chosen by the dtype. For the dtypes R has no native type for (i64, ui64, ui32) that is the bit64::integer64 as_array() returns, since a bare double could not hold the values – and it keeps its class, so is.vector() is FALSE for it.

Use as_array() to obtain an R array that preserves the shape, or nv_convert() to change the dtype of an AnvlArray before coercing. as.vector()'s signature is fixed by the generic, so it takes no check argument and always reports at the default level; call as_array() directly to pick another one.

Usage

# S3 method for class 'AnvlArray'
as.double(x, check = "warn", ...)

# S3 method for class 'AnvlArray'
as.integer(x, check = "warn", ...)

# S3 method for class 'AnvlArray'
as.integer64(x, check = "warn", ...)

# S3 method for class 'AnvlArray'
as.logical(x, check = "warn", ...)

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

Arguments

x

(AnvlArray)
Array to coerce.

check

(character(1) | FALSE)
Forwarded to as_array(); see there for details.

...

Unused.

mode

(character(1))
Must be "any" (the default), meaning the natural R type for the array's dtype. Only present because base::as.vector()'s signature requires it; pick an R type with one of the other methods instead.

Value

(vector)

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
bit64::as.integer64(nv_array(1:6, shape = c(2L, 3L), dtype = "i64"))
#> integer64
#> [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