Method Dispatch of 'squarebrackets'
Source:R/aaa07_squarebrackets_method_dispatch.R
aaa07_squarebrackets_method_dispatch.Rd
This help page gives some additional details regarding the S3 method dispatch
used in 'squarebrackets'.
Atomic vs Recursive
Atomic and recursive objects are quite different from each other in some ways:
homo- or heterogeneous: an atomic object can only have values of one data type.
recursive objects can hold values of any combination of data types.nesting: Recursive objects can be nested, while atomic objects cannot be nested.
copy and coercion effect: One can coerce or copy a subset of a recursive object, without copying the rest of the object.
For atomic objects, however, a coercion or copy operation coerces or copies the entire vector (ignoring attributes).vectorization: most vectorized operations generally work on atomic objects, whereas recursive objects often require loops or apply-like functions.
recursive subsets: Recursive objects distinguish between "regular" subset operations (in base R using
[
,[<-
), and recursive subset operations (in base R using[[
,[[<-
).
See for example the lst_rec method, or thered = TRUE
argument in the \(\ast\)_x
and \(\ast\)_wo
methods.
For atomic objects, these 2 have no meaningful difference (safe for perhaps some minor attribute handling).views: For recursive objects, one can create a View of a recursive subset (see the documentation in the 'mutatomic' package for details).
Subset views do not exist for atomic objects.
Ellipsis
Due to how the S3 method dispatch system works in 'R',
all generic methods have the ellipsis argument (...
).
For the user's safety,
'squarebrackets' does check that the user doesn't accidentally
add arguments that make no sense for that method
(like specifying the inv
argument when calling i_x).