Skip to content

Commit 534f5b7

Browse files
authored
Vignette typos fixes (RConsortium#492)
1 parent f5b23ab commit 534f5b7

File tree

3 files changed

+20
-15
lines changed

3 files changed

+20
-15
lines changed

vignettes/classes-objects.Rmd

+11-6
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ library(S7)
2424
## Validation
2525

2626
S7 classes can have an optional **validator** that checks that the values of the properties are OK.
27-
A validator is a function that takes the object (called `self`) and returns `NULL` if its valid or returns a character vector listing the problems.
27+
A validator is a function that takes the object (called `self`) and returns `NULL` if it's valid or returns a character vector listing the problems.
2828

2929
### Basics
3030

@@ -168,7 +168,7 @@ This makes it possible to use the same property definition for multiple properti
168168

169169
### Default value
170170

171-
The defaults of `new_class()` create an class that can be constructed with no arguments:
171+
The defaults of `new_class()` create a class that can be constructed with no arguments:
172172

173173
```{r}
174174
Empty <- new_class("Empty",
@@ -225,7 +225,7 @@ Range <- new_class("Range",
225225
start = class_double,
226226
end = class_double,
227227
length = new_property(
228-
getter = function(self) self@end - self@start,
228+
getter = function(self) self@end - self@start
229229
)
230230
)
231231
)
@@ -257,6 +257,11 @@ Range <- new_class("Range",
257257
class = class_double,
258258
getter = function(self) self@end - self@start,
259259
setter = function(self, value) {
260+
if (!length(value)) {
261+
# Do nothing if called with the constructor default
262+
# value for this property, a zero-length double vector.
263+
return(self)
264+
}
260265
self@end <- self@start + value
261266
self
262267
}
@@ -392,13 +397,13 @@ Range <- new_class("Range",
392397
end = class_numeric
393398
),
394399
constructor = function(x) {
395-
new_object(S7_object(),
396-
start = min(x, na.rm = TRUE),
400+
new_object(S7_object(),
401+
start = min(x, na.rm = TRUE),
397402
end = max(x, na.rm = TRUE))
398403
}
399404
)
400405
401-
range(c(10, 5, 0, 2, 5, 7))
406+
Range(c(10, 5, 0, 2, 5, 7))
402407
```
403408

404409
A constructor must always end with a call to `new_object()`.

vignettes/compatibility.Rmd

+2-2
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ rle(1:10)
109109
Alternatively you could convert it to the most natural representation using S7:
110110

111111
```{r}
112-
rle <- new_class("rle", properties = list(
112+
new_rle <- new_class("rle", properties = list(
113113
lengths = class_integer,
114114
values = class_atomic
115115
))
@@ -118,7 +118,7 @@ rle <- new_class("rle", properties = list(
118118
To allow existing methods to work you'll need to override `$` to access properties instead of list elements:
119119

120120
```{r}
121-
method(`$`, rle) <- prop
121+
method(`$`, new_rle) <- prop
122122
rle(1:10)
123123
```
124124

vignettes/generics-methods.Rmd

+7-7
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ simple_print(list(1, 2, "x"), diggits = 3)
114114

115115
Occasional it's useful to create a generic without `` because such functions have a useful property: if a call succeeds for one type of input, it will succeed for any type of input.
116116
To create such a generic, you'll need to use the third argument to `new_generic()`: an optional function that powers the generic.
117-
This function has one key property: it must call `call_method()` to actually perform dispatch.
117+
This function has one key property: it must call `S7_dispatch()` to actually perform dispatch.
118118

119119
In general, this property is only needed for very low-level functions with precisely defined semantics.
120120
A good example of such a function is `length()`:
@@ -126,7 +126,7 @@ length <- new_generic("length", "x", function(x) {
126126
```
127127

128128
Omitting `` from the generic signature is a strong restriction as it prevents methods from adding extra arguments.
129-
For this reason, it's should only be used in special situations.
129+
For this reason, it should only be used in special situations.
130130

131131
## Customizing generics
132132

@@ -137,7 +137,7 @@ display <- new_generic("display", "x")
137137
S7_data(display)
138138
```
139139

140-
The most important part of the body is `S7_dispatch()`; this function finds the method the matches the arguments used for dispatch and calls it with the arguments supplied to the generic.
140+
The most important part of the body is `S7_dispatch()`; this function finds the method that matches the arguments used for dispatch and calls it with the arguments supplied to the generic.
141141

142142
It can be useful to customize this body.
143143
The previous section showed one case when you might want to supply the body yourself: dropping `` from the formals of the generic.
@@ -147,7 +147,7 @@ There are three other useful cases:
147147
- To add optional arguments.
148148
- Perform some standard work.
149149

150-
A custom `fun` must always include a call to `call_method()`, which will usually be the last call.
150+
A custom `fun` must always include a call to `S7_dispatch()`, which will usually be the last call.
151151

152152
### Add required arguments
153153

@@ -213,7 +213,7 @@ The only downside to performing error checking is that you constraint the interf
213213

214214
## `super()`
215215

216-
Sometimes it's useful to define a method for in terms of its superclass.
216+
Sometimes it's useful to define a method for a class that relies on the implementation for its superclass.
217217
A good example of this is computing the mean of a date --- since dates represent the number of days since 1970-01-01, computing the mean is just a matter of computing the mean of the underlying numeric vector and converting it back to a date.
218218

219219
To demonstrate this idea, I'll first define a mean generic with a method for numbers:
@@ -256,8 +256,8 @@ This explicitness makes the code easier to understand and will eventually enable
256256

257257
## Multiple dispatch
258258

259-
So far we have focused primarily on single dispatch, i.e. generics where `dispatch_on` is a single string.
260-
It is also possible to supply a length 2 (or more!) vector `dispatch_on` to create a generic that performs multiple dispatch, i.e. it uses the classes of more than one object to find the appropriate method.
259+
So far we have focused primarily on single dispatch, i.e. generics where `dispatch_args` is a single string.
260+
It is also possible to supply a length 2 (or more!) vector `dispatch_args` to create a generic that performs multiple dispatch, i.e. it uses the classes of more than one object to find the appropriate method.
261261

262262
Multiple dispatch is a feature primarily of S4, although S3 includes some limited special cases for arithmetic operators.
263263
Multiple dispatch is heavily used in S4; we don't expect it to be heavily used in S7, but it is occasionally useful.

0 commit comments

Comments
 (0)