S4Vectors icon indicating copy to clipboard operation
S4Vectors copied to clipboard

Should SimpleList inherit list?

Open hpages opened this issue 4 years ago • 1 comments

Suggested by Charles Plessy on the Bioconductor support site.

Could be something like this (roughly):

library(S4Vectors)
setClass("SimpleList2", contains=c("List", "list"))
setMethod("parallel_slot_names", "SimpleList2", function(x) c(".Data", callNextMethod()))
setMethod("as.list", "SimpleList2", function(x) setNames([email protected], names(x)))

Then:

x <- new("SimpleList2", list(a=11:13, b=22:25, c=NULL, d="A"))

length(x)
# [1] 4

names(x)
# [1] "a" "b" "c" "d"

x
# SimpleList2 of length 4
# names(4): a b c d

as.list(x)
# $a
# [1] 11 12 13
# 
# $b
# [1] 22 23 24 25
# 
# $c
# NULL
# 
# $d
# [1] "A"

unlist(x)
#    a    a    a    b    b    b    b    d 
# "11" "12" "13" "22" "23" "24" "25"  "A" 

x[[2]]
# [1] 22 23 24 25

mcols(x)$score <- runif(4)
mcols(x)
# DataFrame with 4 rows and 1 column
#       score
#   <numeric>
# a 0.1695619
# b 0.0302325
# c 0.9856251
# d 0.1155053

purrr::map(x, rev)
# $a
# [1] 13 12 11
# 
# $b
# [1] 25 24 23 22
# 
# $c
# NULL
# 
# $d
# [1] "A"

This is of course a very disruptive change because it touches the internal representation of all SimpleList objects and derivatives (this includes DFrame objects). Which means that all these objects will need to be updated and re-serialized.

Should we do this?

H.

hpages avatar Jan 04 '22 02:01 hpages

My inclination is to say "not now, maybe during work on Bioc 3.16". If I understand correctly this change would bring a form of semantic consistency that has been lacking, unnoticed, for a long time. It seems there are reasonable workarounds. It would be nice to know the historical basis for the gap, that you mentioned on the support site. One motivation for doing it now is that the tooling for reserializing affected objects in the DFrame change is still "warm" and could be mobilized again without a big interruption in work on 3.15. If @hpages thinks this is the case let's discuss further.

vjcitn avatar Jan 04 '22 13:01 vjcitn