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

帅比萌擦擦* 提交于 2019-12-02 07:14:28

问题


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.



来源:https://stackoverflow.com/questions/37897002/include-an-s4-object-from-an-existing-package-as-a-slot-in-a-new-s4-class

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!