I defined a member function for an S4 class (programming language R) which is supposed to add elements to a list, but it does nothing:
setClass("ListHolder",
representation(
.list = "list"
),
prototype(
.list = list()
))
setGeneric("add",
function(this,i) standardGeneric("add")
)
setMethod("add",
signature(this="ListHolder",i="numeric"),
definition = function(this,i){
k <- length([email protected])
[email protected][[k+1]] <- i
})
testListHolder <- function(){
lh <- new("ListHolder")
for(i in 1:10) add(lh,i)
print([email protected])
}
testListHolder()
This will print an empty list. What is going on here?