type: Get the type of the elements of an array-like object

typeR Documentation

Get the type of the elements of an array-like object

Description

The S4Arrays package defines a couple of type() methods to get the type of the elements of a matrix-like or array-like object.

Usage

## S4 method for signature 'ANY'
type(x)

## S4 method for signature 'DataFrame'
type(x)

Arguments

x

For the default type() method: An array-like object. This can be an ordinary array, a SparseArray object from the SparseArray package, a dgCMatrix object from the Matrix package, a DelayedArray object from the DelayedArray package, or any object with an array semantic (i.e. an object for which dim(x) is not NULL).

For the method for DataFrame objects: A DataFrame derivative for which as.data.frame(x) preserves the number of columns. See below for more information.

Details

Note that for an ordinary matrix or array x, type(x) is the same as typeof(x).

On an array-like object x that is not an ordinary array, type(x) is semantically equivalent to typeof(as.array(x)). However, the actual implementation is careful to avoid turning the full array-like object x into an ordinary array, as this would tend to be very inefficient in general. For example, doing so on a big DelayedArray object could easily eat all the memory available on the machine.

On a DataFrame object, type(x) only works if as.data.frame(x) preserves the number of columns, in which case it is semantically equivalent to typeof(as.matrix(as.data.frame(x))). Here too, the actual implementation is careful to avoid turning the full object into a data frame, then into a matrix, for efficiency reasons.

Value

A single string indicating the type of the array elements in x.

See Also

  • The type generic function defined in the BiocGenerics package.

  • SparseArray objects implemented in the SparseArray package.

  • DelayedArray objects implemented in the DelayedArray package.

  • DataFrame objects implemented in the S4Vectors package.

Examples

m <- matrix(rpois(54e6, lambda=0.4), ncol=1200)
type(m)   # integer

x1 <- as(m, "dgCMatrix")
type(x1)  # double

library(SparseArray)
x2 <- SparseArray(m)
type(x2)  # integer

Bioconductor/S4Arrays documentation built on May 1, 2024, 9:27 p.m.