I am creating a list that contained multiple objects and functions.
Each object and function had a similar naming and pattern.
Refer below as the example. In the real case, we have lots more assignments.
lst <- list()
lst$ObjectA <- character()
lst$ObjectB <- character()
lst$ObjectC <- logical()
## by object
lst$.setObjectA <- function(A){
lst$ObjectA <- A
}
lst$.setObjectB <- function(B){
lst$ObjectB <- B
}
lst$.setObjectC <- function(C){
lst$ObjectC <- C
}
So I am wondering if can we do this via loop or the apply family, by creating the vector as below.
object <- c("A", "B", "C", "D", "E")
objectClass <- ("character", "character", "logical", "numeric", "character")
But I don't know how to start, as this involved naming the function and creating the actual function, by codes.
Thank you!