Skip to content

Should SimpleList inherit list? #97

@hpages

Description

@hpages

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(x@.Data, 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions