[Bioc-devel] Delayed Assignment to S4 Slots

Dario Strbenac d@tr7320 @end|ng |rom un|@@ydney@edu@@u
Thu Oct 14 06:00:14 CEST 2021

Good day,

I have an S4 class with some slots in my Bioconductor package. One of the slots stores the range of top variables to try during feature selection (the variables might be ranked by some score, like a t-test). The empty constructor looks like

setMethod("ResubstituteParams", "missing", function()
  new("ResubstituteParams", nFeatures = seq(10, 100, 10), performanceType = "balanced error")

But, someone might have a small omics data set with only 40 features (e.g. CyTOF). Therefore, trying the top 10, 20, ..., 100 is not a good default. A good default would wait until the S4 class is accessed within cross-validation and then, based on the dimensions of the matrix or DataFrame, pick a suitable range. I looked at delayedAssign, but x is described as "a variable name (given as a quoted string in the function call)". It doesn't seem to apply to S4 slots based on my understanding of it.

> r <- ResubstituteParams()
> delayedAssign("r using nFeatures", nrow(measurements))
> measurements <- matrix(1:100, ncol = 10)
> r using nFeatures # Still the value from empty constructor.
 [1]  10  20  30  40  50  60  70  80  90 100

Dario Strbenac
University of Sydney
Camperdown NSW 2050

More information about the Bioc-devel mailing list