s4list: S4/List Conversion

s4listR Documentation

S4/List Conversion

Description

Convert S4 objects to lists and vice versa. Useful for declassing an S4 object while keeping track of it's class using attributes (see section S4 Class Definition Attributes below for more details). Both ListToS4 and S4ToList are recursive functions, affecting all lists/S4 objects contained as sub-lists/sub-objects

Usage

S4ToList(object)

IsS4List(x)

ListToS4(x)

## Default S3 method:
S4ToList(object)

## S3 method for class 'list'
S4ToList(object)

Arguments

object

An S4 object

x

A list with an S4 class definition (“classDef”) attribute

Value

S4ToList: A list with an S4 class definition attribute

IsS4List: TRUE if x is a list with an S4 class definition attribute

ListToS4: An S4 object as defined by the S4 class definition attribute

S4 Class Definition Attributes

S4 classes are scoped to the package and class name. In order to properly track which class a list is generated from in order to build a new one, these function use an attribute to denote the class name and package of origin. This attribute is stored as 1-length character vector named “classDef” and takes the form of “package:class

See Also

ClassKey()

Examples

# Turn an S4 object into a list
pbmc.list <- S4ToList(pbmc_small)
class(pbmc.list)
attributes(pbmc.list)

str(pbmc.list$reductions)

IsS4List(pbmc.list)

pbmc2 <- ListToS4(pbmc.list)
pbmc2
class(pbmc2)
Reductions(pbmc2)
validObject(pbmc2)


SeuratObject documentation built on May 29, 2024, 12:31 p.m.