scalar: Scalars

scalarR Documentation

Scalars

Description

Coerce objects to scalars (vectors of length 1).

Usage

as.scalar(x, mode = "any")
is.scalar(x, mode = "any")

as.scalar.logical(x)

as.scalar.integer(x)

as.scalar.double(x)
as.scalar.numeric(x)

as.scalar.complex(x)

as.scalar.character(x)
as.scalar.string(x)

as.scalar.raw(x)

as.scalar.number(x, strict = TRUE)

Arguments

x

object to be coerced or tested.

mode

character string naming an atomic mode or "any".

strict

TRUE or FALSE, should a complex number that is strictly real (real component is NA or NaN or imaginary component is NA or NaN or 0) be converted to a real number?

Details

as.scalar.logical coerces an object to a vector of type “logical” of length 1.

as.scalar.integer coerces an object to a vector of type “integer” of length 1.

as.scalar.real, as.scalar.double and as.scalar.numeric coerces an object to a vector of type “numeric” of length 1.

as.scalar.complex coerces an object to a vector of type “complex” of length 1.

as.scalar.number coerces an object to a vector of type “numeric” or “complex” of length 1.

as.scalar.string and as.scalar.character coerces an object to a vector of type “character” of length 1.

as.scalar coerces an object to a vector of length 1 of a specified mode.

Value

A vector of length 1.

Examples

## if the type converting from and converting to are identical,
## as.scalar() is a much shorter way of writing what you intend.
as.scalar(c(TRUE, FALSE, NA))
as.scalar(1:100)
as.scalar(1:10 + 0.5)
as.scalar(exp((0+1i) * 6 * (-4:4)))
as.scalar(letters)


## if the type converting from and converting to are not identical, it
## is better to specify the type converting to.
as.scalar.logical(c(TRUE, FALSE, NA))
as.scalar.integer(c(TRUE, FALSE, NA))
as.scalar.numeric(c(TRUE, FALSE, NA))
as.scalar.complex(c(TRUE, FALSE, NA))
as.scalar.character(c(TRUE, FALSE, NA))

as.scalar(TRUE, "character")

ArcadeAntics/essentials documentation built on Nov. 7, 2024, 4:33 p.m.