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 readi64,ui64andui32values that an Rintegercannot hold. It is lossless fori64andui32, butbit64::integer64is itself signed, so aui64value>= 2^63wraps to a negative one (exactly2^63becomesNA); that is warned about, andcheck = "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 thebit64::integer64as_array()returns, since a bare double could not hold the values – and it keeps its class, sois.vector()isFALSEfor 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 toas_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 becausebase::as.vector()'s signature requires it; pick an R type with one of the other methods instead.
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