Is there any guidance on how to implement method dispatch for a vector of R6 objects into a dataframe or list?
This works beautiful for single R6-classes
Proper way to implement S3 dispatch on R6 classes
Implementing S3 method dispatch as suggest in another thread works great for single R6 objects e.g.:
R6list <- R6Class(
"R6list",
public = list(
field1 = "A",
field2 = "B",
initialize = function(x,y) {
self$field1 <- x
self$field2 <- y
},
as.list = function() {
list(
"field1" = self$field1,
"field2" = self$field2
)
}
)
)
as.list.R6list <- function(x, ...) {
x$as.list()
}
mylist1 <- R6list$new("A","B")
mylist2 <- R6list$new("1","2")
as.list(mylist1)
But how should something like the following could be implemented:
as.list(c(mylist1,mylist2))
The returned data frame should have a row for every R6 object and the field names, should be used as column names with their values in every row