MultiFactor: MultiFactor S4 container class

View source: R/MultiFactor-constructors.R

MultiFactorR Documentation

MultiFactor S4 container class

Description

MultiFactor is an S4 class to organize and manage multiple sets of factors, for instance when tracing or converting feature IDs across databases. Methods for MultiFactor aim to follow factor behaviour.

show: Display the object

Analogous to factors. droplevels(MultiFactor) returns a MultiFactor with unused levels removed.

get object levels

Usage

## Constructor for `MultiFactor` objects
MultiFactor(x, levels = NULL, drop.unmatched = TRUE)

asMultiFactor(x, levels = NULL, drop.unmatched = TRUE)

## Accessors
## S4 method for signature 'MultiFactor'
dimnames(x)
## S4 method for signature 'MultiFactor'
dim(x)
## S4 method for signature 'MultiFactor'
names(x)

## S4 method for signature 'MultiFactor'
dictionary(x, ...)
## S4 replacement method for signature 'MultiFactor'
dictionary(x, ...) <- value

## Factor manipulation
## S4 method for signature 'MultiFactor'
levels(x)
## S4 method for signature 'MultiFactor'
unfactor(x)
## S4 method for signature 'MultiFactor'
droplevels(x, exclude = NULL, select = NULL, ...)

## Subsetting
## S4 method for signature 'MultiFactor,ANY,ANY'
x[i, j, ..., drop = TRUE]
## S4 replacement method for signature 'MultiFactor,ANY,ANY,list'
x[i, j, ...] <- value
## S4 method for signature 'MultiFactor,ANY'
x[[i, ...]]
## S4 replacement method for signature 'MultiFactor,ANY,ANY'
x[[i, ...]] <- value
## S4 method for signature 'MultiFactor'
subset(x, subset, select, ...)

## Combining
## S4 method for signature 'MultiFactor'
c(x, ...)

## Coercion
## S4 method for signature 'MultiFactor'
as.list(x, ..., use.names = TRUE)

## S4 method for signature 'MultiFactor'
getEdgeList(x)

## S4 method for signature 'MultiFactor'
show(object)

## S4 method for signature 'MultiFactor'
as.list(x, ..., use.names = TRUE)

## S3 method for class 'MultiFactor'
as.list(x, ..., use.names = TRUE)

Arguments

x, object

MultiFactor on which the method should be applied, or, in case of the constructor MultiFactor(), a named list of data.frames with two named columns each, where elements that share a row indicates thet are adjacent.

levels

an optional named list of vectors of the unique values (as character strings) that x might have taken. The default is the unique set of values taken by lapply(x, as.character), sorted into increasing order of x.

drop.unmatched

⁠Logical scalar⁠ If TRUE (Default), for feature types that are seen at least twice, exclude features that only present in one of their respective link data frames.

i, j, ...

indices specifying elements to extract or replace. Indices are numeric or character vectors or empty (missing) or NULL. Numeric values are coerced to integer or whole numbers as by as.integer or for large values by trunc (and hence truncated towards zero). Character vectors will be matched to the names of the object.

drop

Whether to return a list (Default) or MultiFactor.

value

a replacement character vector of suitable dimensions.

exclude

NULL or ⁠Named character list⁠ of similar structure as levels(MultiFactor). Which levels to drop from output.

select

expression. Which column names to consider. If missing (Default), consider all column names.

subset

⁠logical expression⁠ indicating rows to keep. Must contain variables found as column names.

use.names

⁠Logical scalar⁠, whether output list should contain character (Default) or integer data frame. If FALSE, returns unfactor(x).

Details

The most straightforward way to construct a MultiFactor object is as a named list of named data.frames. The columns of the data.frames indicate the category of factor in that column.

A MultiFactor object presents itself similar to a data.frame, in the sense that level types can be called as columns and individual data.frame components can be called as rows.

Only one of select and exclude should be provided, as they are each others complement.

Value

A MultiFactor

a named list of character vectors.

a named list of character vectors (Default) or integers (use.names = FALSE).

Slots

index

Named list of named integer data frames of at least two columns each. The column names correspond to names in the levels slot. Similar to factors, the integers in those columns correspond to the characters in that level. Accessed through regular list methods (e.g., [, [[).

levels

⁠Named list of character vectors⁠. Accessed through levels(x)

map

⁠(sparse)Matrix⁠ specifying which elements contain which levels. Accesses through dictionary(x).

See Also

  • kegg_link(): for an example of valid input.

BiocGenerics::subset(). weaveWeb() for the AnansiWeb constructor functions that take link data frames.

unfactor()

Examples

# prep input
l <- asMultiFactor(kegg_link())

# Sub-setting is only performed on data frames that contain the arguments
str(subset(x = l, cpd %in% c("C00001", "C00002")))

# Several data frames at the same time:
subset(x = l, ec %in% c("1.2.3.4", "4.3.2.1"))


thomazbastiaanssen/anansi documentation built on June 9, 2025, 3:59 p.m.