You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: Classes_and_Methods/Classes_and_Methods.Rmd
+6-5Lines changed: 6 additions & 5 deletions
Original file line number
Diff line number
Diff line change
@@ -41,7 +41,7 @@ S4 classes/methods
41
41
42
42
## Object Oriented Programming in R
43
43
44
-
- A class is a description of an thing. A class can be defined using `setClass()` in the *methods* package.
44
+
- A class is a description of a thing. A class can be defined using `setClass()` in the *methods* package.
45
45
- An _object_ is an instance of a class. Objects can be created using `new()`.
46
46
- A _method_ is a function that only operates on a certain class of objects.
47
47
- A generic function is an R function which dispatches methods. A generic function typically encapsulates a "generic" concept (e.g. `plot`, `mean`, `predict`, ...)
@@ -88,7 +88,7 @@ class(fit)
88
88
89
89
- S4 and S3 style generic functions look different but conceptually, they are the same (they play the same role).
90
90
- When you program you can write new methods for an existing generic OR create your own generics and associated methods.
91
-
- Of course, if a data type does not exist in R that matches your needs, you can always define a new class along with generics/methods that go with it
91
+
- Of course, if a data type does not exist in R that matches your needs, you can always define a new class along with generics/methods that go with it.
92
92
93
93
## An S3 generic function (in the 'base' package)
94
94
@@ -268,7 +268,8 @@ I say things are "new" meaning that R does not know about them (not that they ar
268
268
A new class can be defined using the `setClass` function
269
269
- At a minimum you need to specify the name of the class
270
270
- You can also specify data elements that are called _slots_
271
-
- You can then define methods for the class with the `setMethod` function Information about a class definition can be obtained with the `showClass` function
271
+
- You can then define methods for the class with the `setMethod` function
272
+
- Information about a class definition can be obtained with the `showClass` function
272
273
273
274
## S4 Class/Method: Polygon Class
274
275
@@ -281,7 +282,7 @@ setClass("polygon",
281
282
y = "numeric"))
282
283
```
283
284
284
-
- The slots for this class are `x`and `y`
285
+
- The slots for this class are `x`and `y`
285
286
286
287
- The slots for an S4 object can be accessed with the `@` operator.
287
288
@@ -340,7 +341,7 @@ plot(p)
340
341
341
342
- <b>Classes</b> define new data types
342
343
343
-
- <b>Methods</b> extend <b>generic functions</b> to specificy the behavior
344
+
- <b>Methods</b> extend <b>generic functions</b> to specify the behavior
344
345
of generic functions on new classes
345
346
346
347
- As new data types and concepts are created, classes/methods provide
0 commit comments