Search code examples
rlistr-s4reference-classdo.call

Use do.call to get information out of a list of RC/S4 objects


I have a defined reference class and a list:

RCclass<-setRefClass("RCclass",field=list(info="character"))
A<-RCclass$new(info="a")
B<-RCclass$new(info="b")
testList<-list(A,B)

do.call(function(x){paste0(x$info)},testList)

The do.call function doesn't look quite right, and it doesn't give me the expected string "ab". However I am not sure how to achieve this. Please share your opinions; thanks!


Solution

  • I found a solution around this:

    Reduce("paste0",(lapply(testList,FUN=function(x)x$info)))