I am having trouble figuring out the proper way to define the [, $, and [[ subset operators for an S4 class.
Can anyone provide me with a basic example of defining these three for an S4 class?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Discover the generic so that we know what we are aiming for
Define a simple class
and implement a method
In action:
There are different strategies for supporting the (implicitly) many signatures, for instance you’d likely also want to support logical and character index values, possibly for both i and j. The most straight-forward is a “facade” pattern where each method does some preliminary coercion to a common type of subset index, e.g.,
integerto allow for re-ordering and repetition of index entries, and then usescallGenericto invoke a single method that does the work of subsetting the class.There are no conceptual differences for
[[, other than wanting to respect the semantics of returning the content rather than another instance of the object as implied by[. For$we haveand
with