Bimap-toTable {AnnotationDbi} | R Documentation

## Methods for manipulating a Bimap object in a data-frame style

### Description

These methods are part of the Bimap interface (see `?Bimap` for a quick overview of the Bimap objects and their interface).

### Usage

      ## Extract all the columns of the map (links + right attributes)
      toTable(x, ...)
      nrow(x)
      ncol(x)
      #dim(x)
      ## S4 method for signature 'FlatBimap'
    head(x, ...)
      ## S4 method for signature 'FlatBimap'
    tail(x, ...)

      ## Extract only the links of the map
      links(x)
      count.links(x)
      nhit(x)

      ## Col names and col metanames
      colnames(x, do.NULL=TRUE, prefix="col")
      colmetanames(x)
      Lkeyname(x)
      Rkeyname(x)
      keyname(x)
      tagname(x)
      Rattribnames(x)
      Rattribnames(x) <- value

### Arguments

`x` | A Bimap object (or a list or an environment for `nhit`).
`...` | Further arguments to be passed to or from other methods (see `head` or `tail` for the details).
`do.NULL` | Ignored.
`prefix` | Ignored.
`value` | A character vector containing the names of the new right attributes (must be a subset of the current right attribute names) or NULL.

### Details

`toTable(x)` turns Bimap object `x` into a data frame (see section "Flat representation of a bimap" in `?Bimap` for a short introduction to this concept). For simple maps (i.e. no tags and no right attributes), the resulting data frame has only 2 columns, one for the left keys and one for the right keys, and each row in the data frame represents a link (or edge) between a left and a right key. For maps with tagged links (i.e. a tag is associated to each link), `toTable(x)` has one additional colmun for the tags and there is still one row per link. For maps with right attributes (i.e. a set of attributes is associated to each right key), `toTable(x)` has one additional colmun per attribute. So for example if `x` has tagged links and 2 right attributes, `toTable(x)` will have 5 columns: one for the left keys, one for the right keys, one for the tags, and one for each right attribute (always the rightmost columns). Note that if at least one of the right attributes is multivalued then more than 1 row can be needed to represent the same link so the number of rows in `toTable(x)` can be strictly greater than the number of links in the map.

`nrow(x)` is equivalent to (but more efficient than) `nrow(toTable(x))`.

`ncol(x)` is equivalent to (but more efficient than) `ncol(toTable(x))`.

`colnames(x)` is equivalent to (but more efficient than) `colnames(toTable(x))`. Columns are named accordingly to the names of the SQL columns where the data are coming from. An important consequence of this that they are not necessarily unique.

`colmetanames(x)` returns the metanames for the column of `x` that are not right attributes. Valid column metanames are `"Lkeyname"`, `"Rkeyname"` and `"tagname"`.

`Lkeyname`, `Rkeyname`, `tagname` and `Rattribnames` return the name of the column (or columns) containing the left keys, the right keys, the tags and the right attributes, respectively.

Like `toTable(x)`, `links(x)` turns `x` into a data frame but the right attributes (if any) are dropped. Note that dropping the right attributes produces a data frame that has eventually less columns than `toTable(x)` and also eventually less rows because now exactly 1 row is needed to represent 1 link.

`count.links(x)` is equivalent to (but more efficient than) `nrow(links(x))`.

`nhit(x)` returns a named integer vector indicating the number of "hits" for each key in `x` i.e. the number of links that start from each key.

### Value

A data frame for `toTable` and `links`.

A single integer for `nrow`, `ncol` and `count.links`.

A character vector for `colnames`, `colmetanames` and `Rattribnames`.

A character string for `Lkeyname`, `Rkeyname` and `tagname`.

A named integer vector for `nhit`.

### Author(s)

H. Pagès

### See Also

Bimap, BimapFormatting, Bimap-envirAPI

### Examples

      library(GO.db)
      x <- GOSYNONYM
      x
      toTable(x)[1:4, ]
      toTable(x["GO:0007322"])
      links(x)[1:4, ]
      links(x["GO:0007322"])

      nrow(x)
      ncol(x)
      dim(x)
      colnames(x)
      colmetanames(x)
      Lkeyname(x)
      Rkeyname(x)
      tagname(x)
      Rattribnames(x)

      links(x)[1:4, ]
      count.links(x)

      y <- GOBPCHILDREN
      nhy <- nhit(y) # 'nhy' is a named integer vector
      identical(names(nhy), keys(y)) # TRUE
      table(nhy)
      sum(nhy == 0) # number of GO IDs with no children
      names(nhy)[nhy == max(nhy)] # the GO ID(s) with the most direct children

      ## Some sanity check
      sum(nhy) == count.links(y) # TRUE

      ## Changing the right attributes of the GOSYNONYM map (advanced
      ## users only)
      class(x) # GOTermsAnnDbBimap
      as.list(x)[1:3]
      colnames(x)
      colmetanames(x)
      tagname(x) # untagged map
      Rattribnames(x)
      Rattribnames(x) <- Rattribnames(x)[3:1]
      colnames(x)
      class(x) # AnnDbBimap
      as.list(x)[1:3]

[Package AnnotationDbi version 1.54.1 Index]