December 2017
Beginner to intermediate
470 pages
12h 29m
English
Since S4 also uses parametric polymorphism (methods belong to functions, not classes) and we have already explained it a couple of times before, we are going to just point out the differences with S3 at this point. First, instead of using the UseMethod() function to register methods with R, we use the setGeneric() function, with the name of the method, and a function that calls the standardGeneric() function inside. This will provide the dispatch mechanism for S4 objects.
To actually create a method, instead of using a naming convention as we do in S3, we actually pass the name of the class and the method to the setMethod() function, as well as the function that should be used as a method. Second, the order ...