row_colnames: Row and column names

Description Usage Arguments Value See Also Examples

Description

Get or set the row or column names of a matrix-like object.

NOTE: This man page is for the rownames, `rownames<-`, colnames, and `colnames<-` S4 generic functions defined in the BiocGenerics package. See ?base::rownames for the default methods (defined in the base package). Bioconductor packages can define specific methods for objects (typically matrix-like) not supported by the default methods.

Usage

1
2
3
4
5
rownames(x, do.NULL=TRUE, prefix="row")
rownames(x) <- value

colnames(x, do.NULL=TRUE, prefix="col")
colnames(x) <- value

Arguments

x

A matrix-like object.

do.NULL, prefix

See ?base::rownames for a description of these arguments.

value

Either NULL or a character vector equal of length equal to the appropriate dimension.

Value

The getters will return NULL or a character vector of length nrow(x) for rownames and length ncol(x) for colnames(x).

See ?base::rownames for more information about the default methods, including how the setters are expected to behave.

Specific methods defined in Bioconductor packages should behave as consistently as possible with the default methods.

See Also

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
## rownames() getter:
rownames  # note the dispatch on the 'x' arg only
showMethods("rownames")
selectMethod("rownames", "ANY")  # the default method

## rownames() setter:
`rownames<-`
showMethods("rownames<-")
selectMethod("rownames<-", "ANY")  # the default method

## colnames() getter:
colnames  # note the dispatch on the 'x' arg only
showMethods("colnames")
selectMethod("colnames", "ANY")  # the default method

## colnames() setter:
`colnames<-`
showMethods("colnames<-")
selectMethod("colnames<-", "ANY")  # the default method

Example output

Loading required package: parallel

Attaching package: 'BiocGenerics'

The following objects are masked from 'package:parallel':

    clusterApply, clusterApplyLB, clusterCall, clusterEvalQ,
    clusterExport, clusterMap, parApply, parCapply, parLapply,
    parLapplyLB, parRapply, parSapply, parSapplyLB

The following objects are masked from 'package:stats':

    IQR, mad, sd, var, xtabs

The following objects are masked from 'package:base':

    Filter, Find, Map, Position, Reduce, anyDuplicated, append,
    as.data.frame, basename, cbind, colMeans, colSums, colnames,
    dirname, do.call, duplicated, eval, evalq, get, grep, grepl,
    intersect, is.unsorted, lapply, lengths, mapply, match, mget,
    order, paste, pmax, pmax.int, pmin, pmin.int, rank, rbind,
    rowMeans, rowSums, rownames, sapply, setdiff, sort, table, tapply,
    union, unique, unsplit, which, which.max, which.min

standardGeneric for "rownames" defined from package "BiocGenerics"

function (x, do.NULL = TRUE, prefix = "row") 
standardGeneric("rownames")
<environment: 0x3bb4518>
Methods may be defined for arguments: x
Use  showMethods("rownames")  for currently available ones.
Function: rownames (package BiocGenerics)
x="ANY"

Method Definition (Class "derivedDefaultMethod"):

function (x, do.NULL = TRUE, prefix = "row") 
{
    dn <- dimnames(x)
    if (!is.null(dn[[1L]])) 
        dn[[1L]]
    else {
        nr <- NROW(x)
        if (do.NULL) 
            NULL
        else if (nr > 0L) 
            paste0(prefix, seq_len(nr))
        else character()
    }
}
<bytecode: 0x3bc1008>
<environment: namespace:base>

Signatures:
        x    
target  "ANY"
defined "ANY"
standardGeneric for "rownames<-" defined from package "base"

function (x, value) 
standardGeneric("rownames<-")
<environment: 0x3c29fd0>
Methods may be defined for arguments: x, value
Use  showMethods("rownames<-")  for currently available ones.
Function: rownames<- (package base)
x="ANY"

Method Definition (Class "derivedDefaultMethod"):

function (x, value) 
{
    if (is.data.frame(x)) {
        row.names(x) <- value
    }
    else {
        dn <- dimnames(x)
        if (is.null(dn)) {
            if (is.null(value)) 
                return(x)
            if ((nd <- length(dim(x))) < 1L) 
                stop("attempt to set 'rownames' on an object with no dimensions")
            dn <- vector("list", nd)
        }
        if (length(dn) < 1L) 
            stop("attempt to set 'rownames' on an object with no dimensions")
        if (is.null(value)) 
            dn[1L] <- list(NULL)
        else dn[[1L]] <- value
        dimnames(x) <- dn
    }
    x
}
<bytecode: 0x3ca5548>
<environment: namespace:base>

Signatures:
        x    
target  "ANY"
defined "ANY"
standardGeneric for "colnames" defined from package "BiocGenerics"

function (x, do.NULL = TRUE, prefix = "col") 
standardGeneric("colnames")
<environment: 0x33676d8>
Methods may be defined for arguments: x
Use  showMethods("colnames")  for currently available ones.
Function: colnames (package BiocGenerics)
x="ANY"

Method Definition (Class "derivedDefaultMethod"):

function (x, do.NULL = TRUE, prefix = "col") 
{
    if (is.data.frame(x) && do.NULL) 
        return(names(x))
    dn <- dimnames(x)
    if (!is.null(dn[[2L]])) 
        dn[[2L]]
    else {
        nc <- NCOL(x)
        if (do.NULL) 
            NULL
        else if (nc > 0L) 
            paste0(prefix, seq_len(nc))
        else character()
    }
}
<bytecode: 0x3347138>
<environment: namespace:base>

Signatures:
        x    
target  "ANY"
defined "ANY"
standardGeneric for "colnames<-" defined from package "base"

function (x, value) 
standardGeneric("colnames<-")
<environment: 0x326cb40>
Methods may be defined for arguments: x, value
Use  showMethods("colnames<-")  for currently available ones.
Function: colnames<- (package base)
x="ANY"

Method Definition (Class "derivedDefaultMethod"):

function (x, value) 
{
    if (is.data.frame(x)) {
        names(x) <- value
    }
    else {
        dn <- dimnames(x)
        if (is.null(dn)) {
            if (is.null(value)) 
                return(x)
            if ((nd <- length(dim(x))) < 2L) 
                stop("attempt to set 'colnames' on an object with less than two dimensions")
            dn <- vector("list", nd)
        }
        if (length(dn) < 2L) 
            stop("attempt to set 'colnames' on an object with less than two dimensions")
        if (is.null(value)) 
            dn[2L] <- list(NULL)
        else dn[[2L]] <- value
        dimnames(x) <- dn
    }
    x
}
<bytecode: 0x31e6e28>
<environment: namespace:base>

Signatures:
        x    
target  "ANY"
defined "ANY"

BiocGenerics documentation built on April 17, 2021, 6:01 p.m.