Include an S4 object from an existing package as a

2019-03-01 21:57发布

问题:

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

回答1:

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



回答2:

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.



标签: r class s4