Learn R Programming

flint (version 0.1.0)

asVector: Coerce an Object to a Vector Class

Description

A generalization of as.vector enabling coercion from and to flint vector classes (in addition to basic vector classes) and providing more uniform handling of attributes.

Usage

asVector(x, mode = "any", strict = TRUE)

Value

The result of coercing x to the target class indicated by

mode.

Arguments

x

an R object coercible to the target class.

mode

a character string indicating the target class.

strict

a logical indicating if attributes of x should be discarded and if the class of the return value must match the target class exactly (and hence not be a subclass of the target class).

Details

Argument mode can be one of the basic vector classes "raw", "logical", "integer", "numeric" (synonym "double"), "complex", "character", "list", and "expression"; one of the flint vector classes "ulong", "slong", "fmpz", "fmpq", "mag", "arf", "acf", "arb", and "acb"; or one of "any", "vector", and "flint", indicating the vector class, basic vector class, and flint vector class “nearest” the class of x. Note that as.vector supports mode equal to "name" (synonym "symbol") or "pairlist". asVector does not: names and pairlists are not vectors!

See Also

Virtual class vector and related functions as.vector and as.

Examples

Run this code
str(J  <- diag(ulong(1L), 2L))

as.integer(J)
as.vector(J, "integer")
as(J, "integer")
asVector(J, "integer")
asVector(J, "integer", FALSE)

setClass("ulongExtension", contains = "ulong")
str(J. <- new("ulongExtension", J))

str(asVector(J , "ulong"))
str(asVector(J., "ulong"))
str(asVector(J , "ulong", FALSE))
str(asVector(J., "ulong", FALSE))

Run the code above in your browser using DataLab