View source: R/reduced.dim.matrix.R

reduced.dim.matrix | R Documentation |

A matrix class that retains its attributes upon being subsetted or combined.
This is useful for storing metadata about a dimensionality reduction result alongside the matrix,
and for ensuring that the metadata persists when the matrix is stored inside `reducedDims`

.

`reduced.dim.matrix(x, ...)`

will return a reduced.dim.matrix object, given a matrix input `x`

.
Arguments in `...`

should be named and are stored as custom attributes in the output.
Any arguments named `dim`

or `dimnames`

are ignored.

`x[i, j, ..., drop=FALSE]`

will subset a reduced.dim.matrix `x`

in the same manner as a base matrix.
The only difference is that a reduced.dim.matrix will be returned, retaining any custom attributes in `x`

.
Note that no custom attributes are retained if the return value is a vector with `drop=TRUE`

.

`rbind(...)`

will combine multiple reduced.dim.matrix inputs in `...`

by row,
while `cbind(...)`

will combine those inputs by column.

If the custom attributes are the same across all objects `...`

,
a reduced.dim.matrix is returned containing all combined rows/columns as well as the custom attributes.

If the custom attributes are different, a warning is issued. A matrix is returned containing all combined rows/columns; no custom attributes are retained.

Aaron Lun

`reducedDims`

, to store these objects in a SingleCellExperiment.

```
# Typical PC result, with metadata stored in the attributes:
pc <- matrix(runif(500), ncol=5)
attr(pc, "sdev") <- 1:100
attr(pc, "rotation") <- matrix(rnorm(20), ncol=5)
# Disappears upon subsetting and combining!
attributes(pc[1:10,])
attributes(rbind(pc, pc))
# Transformed into a reduced.dim.matrix:
rd.pc <- reduced.dim.matrix(pc)
attributes(rd.pc[1:10,])
attributes(rbind(rd.pc, rd.pc))
```

Embedding an R snippet on your website

Add the following code to your website.

For more information on customizing the embed code, read Embedding Snippets.