type | R Documentation |
Get or set the type of an object.
Note that type
and type<-
are defined as S4 generic
functions and what type means exactly (and what type()
returns) depends on the objects for which the type
and/or
type<-
methods are defined.
type(x)
type(x) <- value
## Methods defined in the BiocGenerics package:
## S4 method for signature 'vector'
type(x)
## S4 method for signature 'array'
type(x)
## S4 method for signature 'factor'
type(x) # returns "character"
## S4 method for signature 'data.frame'
type(x)
## S4 replacement method for signature 'vector'
type(x) <- value
## S4 replacement method for signature 'array'
type(x) <- value
x |
Any object for which the |
value |
The type to set on |
On an ordinary vector, matrix, or array x
, type(x)
returns
typeof(x)
.
On a data frame x
where all the columns are ordinary vectors
or factors, type(x)
is semantically equivalent to
typeof(as.matrix(x))
. However, the actual implementation is
careful to avoid turning the full data frame x
into a matrix,
as this would tend to be very inefficient in general.
Note that for a matrix-like or array-like object, type(x)
returns the type of the elements in the object.
See ?S4Arrays::type
for more information.
type(x)
is expected to return the type of x
as a single
string i.e. as a character vector of length 1.
showMethods
for displaying a summary of the
methods defined for a given generic function.
selectMethod
for getting the definition of
a specific method.
type,ANY-method in the S4Arrays
package for the default type
method.
type,DataFrame-method in the S4Arrays
package, and type,PairwiseAlignments-method in
the pwalign package, for examples of specific type
methods (defined for DataFrame and
PairwiseAlignments objects, respectively).
BiocGenerics for a summary of all the generics defined in the BiocGenerics package.
type
showMethods("type")
`type<-`
showMethods("type<-")
## The BiocGenerics package defines methods for ordinary vectors, arrays,
## and data frames:
m <- matrix(11:22, nrow=3)
type(m) # equivalent to 'typeof(m)' or 'storage.mode(m)'
type(m) <- "raw" # equivalent to 'storage.mode(m) <- "raw"'
m
type(m)
selectMethod("type", "array")
selectMethod("type<-", "array")
df <- data.frame(a=44:49, b=letters[1:6], c=c(TRUE, FALSE))
stopifnot(identical(type(df), typeof(as.matrix(df))))
## Examples of methods defined in other packages:
library(S4Arrays)
showMethods("type")
selectMethod("type", "ANY") # the default "type" method
library(pwalign)
showMethods("type")
## The type() method for PairwiseAlignments objects:
selectMethod("type", "PairwiseAlignments")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.