How to create an array of your objects in R?
Suppose I have a class:

setClass("Runner", representation(name="character",time="numeric",place="numeric"), prototype(time=0,place=0) ) a = readline("Enter amount of person") foo = list() for(i in 1:a){ u = readline("Name") t = readline("Time") t = as.integer(t) tmp = new ("Runner", name = u, time = t ) foo[i]=tmp } 

foo is my array of objects. But when compiling the error:

In `[<-` (` * tmp * `, i, value =): implicit list embedding of S4 objects is deprecated

    1 answer 1

    It is enough to replace [] with [[]] when assigning a new list item. Also the size of the list is better to determine in advance.

    Note that the result of the readline operation is always a character , while in the code it is meant that it is a number.

     setClass("Runner", representation(name="character",time="numeric",place="numeric"), prototype(time=0,place=0) ) a = as.numeric(readline("Enter amount of person:")) foo = vector("list", a) for(i in 1:a) { u = readline("Name") t = readline("Time") t = as.integer(t) tmp = new ("Runner", name = u, time = t ) foo[[i]] = tmp }