I suspect the return value of caret::train
is not an S4 object, rather an S3 object. Use setOldClass("train")
, which should then register the train
class for use with S4 slots. This works:
setOldClass("train")
trn <- train(data.frame(x=1:3, y=1:3), 1:3)
isS4(trn)
# [1] FALSE
new("TrainResults", successrate=1, plsFit=trn)
# An object of class "TrainResults"
# ... omitted a bunch of output
The basic data types (e.g. numeric
, etc.) are all already pre-registered as S4 classes so you don't need to do that for those to work as S4 slots.
Note you have a typo in your code as well (lower case R in Train*r*esulsts
).