Why S4?
Why S4?
function overloading
to throttle the number of functions required to interact with objectsWhy S4?
function overloading
to throttle the number of functions required to interact with objectsWhy S4?
function overloading
to throttle the number of functions required to interact with objectsJohn Chambers
himselfWhy S4?
function overloading
to throttle the number of functions required to interact with objectsJohn Chambers
himselfBioconductor
projectWhy S4?
function overloading
to throttle the number of functions required to interact with objectsJohn Chambers
himselfBioconductor
projectWhy S4?
function overloading
to throttle the number of functions required to interact with objectsJohn Chambers
himselfBioconductor
projectWhy S4?
function overloading
to throttle the number of functions required to interact with objectsJohn Chambers
himselfBioconductor
project@
Why S4?
function overloading
to throttle the number of functions required to interact with objectsJohn Chambers
himselfBioconductor
project@
methods
packageHow do you create a class?
How do you create a class?
setClass("myClass", slots= ...., contains =...., prototype =....)
How do you create a class?
setClass("myClass", slots= ...., contains =...., prototype =....)
How do you create a generic for the class?
How do you create a class?
setClass("myClass", slots= ...., contains =...., prototype =....)
How do you create a generic for the class?
setGeneric(name, def)
How do you create a class?
setClass("myClass", slots= ...., contains =...., prototype =....)
How do you create a generic for the class?
setGeneric(name, def)
How do you create a method for the generic?
How do you create a class?
setClass("myClass", slots= ...., contains =...., prototype =....)
How do you create a generic for the class?
setGeneric(name, def)
How do you create a method for the generic?
setMethod(f, signature, definition)
If the prototype is optional, why should we use it?
If the prototype is optional, why should we use it?
This allows you to pass in default values for class slots (attributes)
If the prototype is optional, why should we use it?
This allows you to pass in default values for class slots (attributes)
I want to build on top of another class. Is there a workaround to copy and pasting attributes from one class to another?
If the prototype is optional, why should we use it?
This allows you to pass in default values for class slots (attributes)
I want to build on top of another class. Is there a workaround to copy and pasting attributes from one class to another?
Why, yes there is! The contains
argument in setClass
allows you to specify the class to inherit from
If the prototype is optional, why should we use it?
This allows you to pass in default values for class slots (attributes)
I want to build on top of another class. Is there a workaround to copy and pasting attributes from one class to another?
Why, yes there is! The contains
argument in setClass
allows you to specify the class to inherit from
If I can use
new()
to construct an object, why do I bother to create a constructor?
If the prototype is optional, why should we use it?
This allows you to pass in default values for class slots (attributes)
I want to build on top of another class. Is there a workaround to copy and pasting attributes from one class to another?
Why, yes there is! The contains
argument in setClass
allows you to specify the class to inherit from
If I can use
new()
to construct an object, why do I bother to create a constructor?
Apparently programmers want other people to use their stuff. Constructors politely define the slots (attributes) that require data, which you then assign to new()
in the body of the constructor
I don't want this use of my class to break, how do I validate that an object has the correct attributes?
I don't want this use of my class to break, how do I validate that an object has the correct attributes?
setValidity(Class, method)
, where the method is a function that contains the validity checks. You define this once and it is associated with object construction going forward. It is not triggered if an object is modified
I don't want this use of my class to break, how do I validate that an object has the correct attributes?
setValidity(Class, method)
, where the method is a function that contains the validity checks. You define this once and it is associated with object construction going forward. It is not triggered if an object is modified
Well, if I can't validate on modificaiton, what do I do?
I don't want this use of my class to break, how do I validate that an object has the correct attributes?
setValidity(Class, method)
, where the method is a function that contains the validity checks. You define this once and it is associated with object construction going forward. It is not triggered if an object is modified
Well, if I can't validate on modificaiton, what do I do?
This is where we build on the idea of helpers and wrap an accessor in a function that also validates the inputs to underlying attributes
What was the point of a generic again?
What was the point of a generic again?
Generics are functions that describe behavior found across multiple classes of objects. By decomposing functions into generics and methods we solve the issue of function overpopulation
What was the point of a generic again?
Generics are functions that describe behavior found across multiple classes of objects. By decomposing functions into generics and methods we solve the issue of function overpopulation
And the S4 syntax for creating one?
What was the point of a generic again?
Generics are functions that describe behavior found across multiple classes of objects. By decomposing functions into generics and methods we solve the issue of function overpopulation
And the S4 syntax for creating one?
setGeneric(name, def)# ExamplesetGeneric("myGeneric", function(x) standardGeneric("myGeneric"))
What was the point of a method again?
What was the point of a method again?
A method is a function for a specific class of object. Which means as a programmer you are still writing up functions for every class but for the user the interface is standardized through the generic
What was the point of a method again?
A method is a function for a specific class of object. Which means as a programmer you are still writing up functions for every class but for the user the interface is standardized through the generic
And the S4 syntax for creating one?
What was the point of a method again?
A method is a function for a specific class of object. Which means as a programmer you are still writing up functions for every class but for the user the interface is standardized through the generic
And the S4 syntax for creating one?
setMethod(f, signature, definition)#ExamplesetMethod("myGeneric", "Person", function(x) { # method implementation})
I've overloaded generic functions with a bunch of class specific methods. Now what?
I've overloaded generic functions with a bunch of class specific methods. Now what?
The generic function looks at the class and lookups up the method!
I've overloaded generic functions with a bunch of class specific methods. Now what?
The generic function looks at the class and lookups up the method!
What if I built up classes one on top of the other? You know, like evolution or something?
--
Well, the generic will search for the methods assigned to the classes and use the one that is "closest". If there there is not a closest, then it picks the method that comes earliest in the alphabet.
How exactly do these two system allow interactions?
How exactly do these two system allow interactions?
Well, you can assign an S3 object to a S4 slot
or build on top of an S3 object by using contains
.
How exactly do these two system allow interactions?
Well, you can assign an S3 object to a S4 slot
or build on top of an S3 object by using contains
.
Sounds easy! Really glad there isn't a fancy function required to allow this to work!!
How exactly do these two system allow interactions?
Well, you can assign an S3 object to a S4 slot
or build on top of an S3 object by using contains
.
Sounds easy! Really glad there isn't a fancy function required to allow this to work!!
Silly, of course there is a fancy function required! Seems painless though
setOldClass(Classes)
setClass("factor", contains = "integer", slots = c( levels = "character" ), prototype = structure( integer(), levels = character() ))setOldClass("factor", S4Class = "factor")
How exactly do these two system allow interactions?
Well, you can assign an S3 object to a S4 slot
or build on top of an S3 object by using contains
.
Sounds easy! Really glad there isn't a fancy function required to allow this to work!!
Silly, of course there is a fancy function required! Seems painless though
setOldClass(Classes)
setClass("factor", contains = "integer", slots = c( levels = "character" ), prototype = structure( integer(), levels = character() ))setOldClass("factor", S4Class = "factor")
Ok, we've got a way to inherit attributes from S3 Objects. What about importing S3 generics to S4?
How exactly do these two system allow interactions?
Well, you can assign an S3 object to a S4 slot
or build on top of an S3 object by using contains
.
Sounds easy! Really glad there isn't a fancy function required to allow this to work!!
Silly, of course there is a fancy function required! Seems painless though
setOldClass(Classes)
setClass("factor", contains = "integer", slots = c( levels = "character" ), prototype = structure( integer(), levels = character() ))setOldClass("factor", S4Class = "factor")
Ok, we've got a way to inherit attributes from S3 Objects. What about importing S3 generics to S4?
setGeneric(name, def)
Does this break its use for S3 methods?
S4 vs S3
S4 vs S3
bioconductor
S4 vs S3
bioconductor
R6 vs S3
$
to pipe method callsKeyboard shortcuts
↑, ←, Pg Up, k | Go to previous slide |
↓, →, Pg Dn, Space, j | Go to next slide |
Home | Go to first slide |
End | Go to last slide |
Number + Return | Go to specific slide |
b / m / f | Toggle blackout / mirrored / fullscreen mode |
c | Clone slideshow |
p | Toggle presenter mode |
t | Restart the presentation timer |
?, h | Toggle this help |
Esc | Back to slideshow |