Casey Dunn
Casey Dunn

Reputation: 311

Include an S4 object from an existing package as a slot in a new S4 class

I am writing an S4 class called Expression and would like to include an S4 object, DESeq2 = "DESeqDataSet" as a slot:

setClass(
Class = "Expression",
representation = representation (
    species = "character", 
    edgeR = "DGEList",
    DESeq2 = "DESeqDataSet",
    lengths = "matrix",
    individuals = "vector",
    treatments = "vector",
    id = "vector",
    samples = "vector",
    sample_prep = "vector",
    genome_type = "vector",
    molecule_type = "vector",
    blast_hit =  "vector",
    rRNA = "vector",
    protein = "vector"
))

When I check the package, though, I get the following Warning:

Found the following significant warnings:
  Warning: undefined slot classes in definition of "Expression": DESeq2(class "DESeqDataSet")

The class works fine (ie, there are now errors), but I would like to fix all warnings in our code.

The package with the DESeqDataSet object (DESeq2, also the name we have given to the slot) is imported in the package DESCRIPTION file. Do I need to do something else to make its contents available for use in a slot? For example, I have used setOldClass() to make S3 classes available for use in S4 slots.

Here is an example of a travis-ci build that throws the warning - https://travis-ci.org/caseywdunn/agalmar/builds/138564256

The full code that is giving the problem is at https://github.com/caseywdunn/agalmar/blob/a7c4013fcb5c924cfd6e1aa8e99f182ceec6fe20/R/utility_functions.R

Upvotes: 3

Views: 810

Answers (2)

user2167441
user2167441

Reputation: 51

You can solve your problem by using the "contains" parameter of the setClass function. Contains can define any types or objects.

setClass(
Class = "Expression",
representation = representation (
    species = "character", 
    edgeR = "DGEList",
    DESeq2 = "DESeqDataSet",
    lengths = "matrix",
    individuals = "vector",
    treatments = "vector",
    id = "vector",
    samples = "vector",
    sample_prep = "vector",
    genome_type = "vector",
    molecule_type = "vector",
    blast_hit =  "vector",
    rRNA = "vector",
    protein = "vector"
    ), 
    contains = c("DGEList", "DESeqDataSet")
)

Hope this helps.

Upvotes: 1

Martin Morgan
Martin Morgan

Reputation: 46856

Class definitions need to be imported, just like functions, generics, and methods. So in the NAMESPACE file say

importClassesFrom("DESeq2", "DESeqDataSet")

I believe the roxygen2 notation is @importClassesFrom DESeq2 DESeqDataSet

Upvotes: 5

Related Questions