Should I create a new class or using Common Classes
1
0
Entering edit mode
@shangguandong1996-21805
Last seen 2.1 years ago
China

Hi, everyone.

Recently, I am writing a package and want to submit to bioconductor in the future. I almost finish the function, but I have not write a calss or generic function. Becasue I am new to writing package or R class. For now, my output of function are Granges class or data.frame, and my operation is about peakAnno, extract metaInfo and do some calculation using dply. For now, I just want my calss can store some meta info, like paramter and peakAnno result based on GRanges.

So I am wondering whether I should write my own class or using common class like Common Bioconductor Methods and Classes. I have noticed Granges calss have metadata attribute, which is a list. mabye I can write some meta info into it. like

> peak@metadata$"test" <- "a"
> peak@metadata
$test
[1] "a"

But I also noticed some package I always used, like DiffBind, ChIPseeker created their own class.

Please forgive me if I misunderstand something :)

Best wishes

Guandong Shang

GenomicRanges • 995 views
ADD COMMENT
2
Entering edit mode

Note that using direct slot access (with @) is a bad idea and strongly discouraged. Please always use accessor functions instead e.g.

metadata(peak)$test <- "a"
metadata(peak)

Cheers,

H.

ADD REPLY
1
Entering edit mode
@laurent-gatto-5645
Last seen 6 weeks ago
Belgium

Dear Guandong Shang - In my experience, there is no need to create a class if those that exists are a good fit for your use-case. If at some point, you feel that your needs aren't met by what exists, then you might consider creating a new one, but that doesn't sound the case from your message above.

Same applies to methods and generics. If the name of the function is very general and is also applicable in other contexts, than a generic function and class-specific methods becomes relevant - in such cases, it's always good to check if such a generic isn't already available (for example in BiocGenerics). Otherwise, a function works perfectly well.

ADD COMMENT

Login before adding your answer.

Traffic: 633 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6