Skip to contents

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 class 'MultiFactor'
dimnames(x)
# S4 method for class 'MultiFactor'
dim(x)
# S4 method for class 'MultiFactor'
names(x)

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

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

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

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

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

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

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

# S4 method for class '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).

Value

A MultiFactor

a named list of character vectors.

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

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.

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

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")))
#> Formal class 'MultiFactor' [package "anansi"] with 3 slots
#>   ..@ index :List of 2
#>   .. ..$ ec2ko :'data.frame':	8156 obs. of  2 variables:
#>   .. .. ..$ ec: int [1:8156] 1 2 3 4 5 6 7 8 9 10 ...
#>   .. .. ..$ ko: int [1:8156] 1 2 3 4 4 5 6 7 8 9 ...
#>   .. ..$ ec2cpd:'data.frame':	0 obs. of  2 variables:
#>   .. .. ..$ ec : int(0) 
#>   .. .. ..$ cpd: int(0) 
#>   ..@ levels:List of 3
#>   .. ..$ ec : chr [1:4825] "1.1.1.1" "1.1.1.2" "1.1.1.3" "1.1.1.4" ...
#>   .. ..$ ko : chr [1:7270] "K00001" "K00002" "K00003" "K00004" ...
#>   .. ..$ cpd: chr [1:6754] "C00001" "C00002" "C00003" "C00004" ...
#>   ..@ map   :Formal class 'dgCMatrix' [package "Matrix"] with 6 slots
#>   .. .. ..@ i       : int [1:4] 0 1 0 1
#>   .. .. ..@ p       : int [1:4] 0 2 3 4
#>   .. .. ..@ Dim     : int [1:2] 2 3
#>   .. .. ..@ Dimnames:List of 2
#>   .. .. .. ..$ : chr [1:2] "ec2ko" "ec2cpd"
#>   .. .. .. ..$ : chr [1:3] "ec" "ko" "cpd"
#>   .. .. ..@ x       : num [1:4] 4825 4825 7270 6754
#>   .. .. ..@ factors : list()

# Several data frames at the same time:
subset(x = l, ec %in% c("1.2.3.4", "4.3.2.1"))
#> A list of class MultiFactor,
#>     3 feature types across 2 edge lists.
#> 
#>          ec   ko  cpd
#> ec2ko  4825 7270    .
#> ec2cpd 4825    . 6754
#> 
#> Values represent unique feature names in that edge list.
#> 
#> Levels:
#> 
#> ec  : 4825 Levels: 1.1.1.1 1.1.1.2 ... 1.14.13.253 
#> ko  : 7270 Levels: K00001 K00002 ... K28089 
#> cpd : 6754 Levels: C00001 C00002 ... C22998