new2(class, ...)
An alternative version of new
to create
objects based on a list of values.
setClass('A', contain='character', representation(x='numeric', y='character'))# identical behaviour with standard callsidentical(new('A'), new2('A'))[1] TRUEidentical(new('A', x=1), new2('A', x=1))[1] TRUE# but if passing that are names not slotsidentical(new('A'), new2('A', b=1))[1] TRUEidentical(new('A', x=1), new2('A', x=1, b=3))[1] TRUEidentical(new('A', x=1), new2('A', x=1, b=3))[1] TRUE# standard `new` would coerce first unnamed argument into parent of 'A' (i.e. 'character')new('A', list(x=1))An object of class "A" [1] "1" Slot "x": numeric(0) Slot "y": character(0)new('A', list(x=1, y='other'))An object of class "A" [1] "1" "other" Slot "x": numeric(0) Slot "y": character(0)# `new2` rather use it to initialise the slots it can find in the listidentical(new('A', x=1), new2('A', list(x=1)))[1] TRUEidentical(new('A', x=1, y='other'), new2('A', list(x=1, y='other')))[1] TRUE