tidy-motifs {universalmotif} | R Documentation

## Tidy manipulation of motifs.

### Description

Tidy manipulation of motifs.

### Usage

    to_df(motifs, extrainfo = TRUE)

    update_motifs(motif_df, extrainfo = TRUE, force = FALSE)

    to_list(motif_df, extrainfo = TRUE, force = FALSE)

    requires_update(motifs, extrainfo = TRUE)

### Arguments

`motifs` | List of motifs.
`extrainfo` | Use the `extrainfo` slot in the tidy `data.frame`. The column names will be taken from the character vectors themselves, and unnamed elements will be assigned a unique name. To add elements to the slot, simply create new columns in the `data.frame`. Note that these will be coerced into characters. If `extrainfo` is not set to `TRUE` in `to_df()`, then the contents of the slot will not be transferred to the `data.frame`. If `extrainfo` is not set to `TRUE` in `update_motifs()` or `to_list()`, then the extra columns will be discarded.
`motif_df` | Motif `data.frame` generated by `to_df()`.
`force` | Whether to coerce non-character data types into characters for inclusion in `extrainfo`. If `force` is `FALSE` (the default), columns which are not of type "character", "numeric", or "integer" (for example, list columns, or logical values), will not be added to the motif `extrainfo` slot, but will be passed onto the returned `universalmotif_df` unchanged. Setting `force = TRUE` coerces these values into a character, adding them to the `extrainfo` slot, and updating the `universalmotif_df` columns to reflect this coercion. In other words, forcing inclusion of these data is destructive and will change the column values. Use with caution.

### Value

For `to_df()`: a `data.frame` with the exposed slots as columns.

For `update_motifs()`: the updated `data.frame`.

For `requires_update()`: `TRUE` if the motifs are out of date, `FALSE` if otherwise. Note that this function uses `identical()` to check for this, which can be quite slow for large datasets. It is usually just as fast to simply run `update_motifs()` in such cases.

For `to_list()`: a list of motifs.

### Author(s)

Benjamin Jean-Marie Tremblay, benjamin.tremblay@uwaterloo.ca

### Examples

    ## Not run:
    library(universalmotif)
    library(dplyr)

    m <- c(create_motif(name = "motif A"), create_motif(name = "motif B"))

    # Change the names of the motifs using the tidy way:
    m <- m %>%
       to_df() %>%
       mutate(name = paste0(name, "-2")) %>%
       to_list()

    # Add your own metadata to be stored in the extrainfo slot:
    m_df <- to_df(m)
    m_df$MyMetadata <- c("Info_1", "Info_2")
    m <- to_list(m_df, extrainfo = TRUE)

    ## End(Not run)

[Package universalmotif version 1.10.2 Index]