I basically would like to create a new type of list with Reference Class. Instead of using S3 object, I also want to avoid static methods and define private functions within the reference class, such as:
weirdList<-setRefClass("weirdList"
,contains="list"
,methods=list(
,initialize=function(...){
return(list(...))
},
sumup=function(){
sum(list()) # don't know how to write this
}))
new_list<-weirdList(a=1,b=2,c=3)
new_list
# expecting output:
# $a
# [1] 1
#
# $b
# [1] 2
#
# $c
# [1] 3
new_list$sumup()
# I want to output 6
Obviously the above doesn't work. I find it difficult to "clone" or modify a primitive methods. Does anyone know how to do it? Thanks in advance.