Skip to content

Commit 89ff0c7

Browse files
authored
Use CamelCase for all class names in docs and vignettes. (RConsortium#485)
* Project-level canonical markdown `wrap: sentence` * update all `new_class()` usage in vignettes * update all `new_class()` usage in docs/examples * redocument * enable `workflow_dispatch` on R-CMD-check CI action * whitespace
1 parent 4ced878 commit 89ff0c7

31 files changed

+275
-272
lines changed

.github/workflows/R-CMD-check.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
# check-standard.yaml is likely a better choice.
66
# usethis::use_github_action("check-standard") will install it.
77
on:
8+
workflow_dispatch:
89
push:
910
branches: [main, master]
1011
pull_request:

R/S3.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
#'
1818
#' ```R
1919
#' method(my_generic, new_S3_class("factor")) <- function(x) "A factor"
20-
#' new_class("my_class", properties = list(types = new_S3_class("factor")))
20+
#' new_class("MyClass", properties = list(types = new_S3_class("factor")))
2121
#' new_union("character", new_S3_class("factor"))
2222
#' ```
2323
#'

R/S4.R

+4-4
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@
1212
#' standardGeneric("S4_generic")
1313
#' })
1414
#'
15-
#' foo <- new_class("foo")
16-
#' S4_register(foo)
17-
#' method(S4_generic, foo) <- function(x) "Hello"
15+
#' Foo <- new_class("Foo")
16+
#' S4_register(Foo)
17+
#' method(S4_generic, Foo) <- function(x) "Hello"
1818
#'
19-
#' S4_generic(foo())
19+
#' S4_generic(Foo())
2020
S4_register <- function(class, env = parent.frame()) {
2121
if (!is_class(class)) {
2222
msg <- sprintf("`class` must be an S7 class, not a %s", obj_desc(class))

R/class.R

+10-10
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#'
1010
#' @param name The name of the class, as a string. The result of calling
1111
#' `new_class()` should always be assigned to a variable with this name,
12-
#' i.e. `foo <- new_class("foo")`.
12+
#' i.e. `Foo <- new_class("Foo")`.
1313
#' @param parent The parent class to inherit behavior from.
1414
#' There are three options:
1515
#'
@@ -56,25 +56,25 @@
5656
#' @export
5757
#' @examples
5858
#' # Create an class that represents a range using a numeric start and end
59-
#' range <- new_class("range",
59+
#' Range <- new_class("Range",
6060
#' properties = list(
6161
#' start = class_numeric,
6262
#' end = class_numeric
6363
#' )
6464
#' )
65-
#' r <- range(start = 10, end = 20)
65+
#' r <- Range(start = 10, end = 20)
6666
#' r
6767
#' # get and set properties with @
6868
#' r@start
6969
#' r@end <- 40
7070
#' r@end
7171
#'
7272
#' # S7 automatically ensures that properties are of the declared types:
73-
#' try(range(start = "hello", end = 20))
73+
#' try(Range(start = "hello", end = 20))
7474
#'
7575
#' # But we might also want to use a validator to ensure that start and end
7676
#' # are length 1, and that start is < end
77-
#' range <- new_class("range",
77+
#' Range <- new_class("Range",
7878
#' properties = list(
7979
#' start = class_numeric,
8080
#' end = class_numeric
@@ -89,10 +89,10 @@
8989
#' }
9090
#' }
9191
#' )
92-
#' try(range(start = c(10, 15), end = 20))
93-
#' try(range(start = 20, end = 10))
92+
#' try(Range(start = c(10, 15), end = 20))
93+
#' try(Range(start = 20, end = 10))
9494
#'
95-
#' r <- range(start = 10, end = 20)
95+
#' r <- Range(start = 10, end = 20)
9696
#' try(r@start <- 25)
9797
new_class <- function(
9898
name,
@@ -322,8 +322,8 @@ str.S7_object <- function(object, ..., nest.lev = 0) {
322322
#' @returns An [S7 class][new_class].
323323
#' @export
324324
#' @examples
325-
#' foo <- new_class("foo")
326-
#' S7_class(foo())
325+
#' Foo <- new_class("Foo")
326+
#' S7_class(Foo())
327327
S7_class <- function(object) {
328328
attr(object, "S7_class", exact = TRUE)
329329
}

R/convert.R

+14-14
Original file line numberDiff line numberDiff line change
@@ -41,36 +41,36 @@
4141
#' is not possible.
4242
#' @export
4343
#' @examples
44-
#' foo1 <- new_class("foo1", properties = list(x = class_integer))
45-
#' foo2 <- new_class("foo2", foo1, properties = list(y = class_double))
44+
#' Foo1 <- new_class("Foo1", properties = list(x = class_integer))
45+
#' Foo2 <- new_class("Foo2", Foo1, properties = list(y = class_double))
4646
#'
4747
#' # Downcasting: S7 provides a default implementation for coercing an object
4848
#' # to one of its parent classes:
49-
#' convert(foo2(x = 1L, y = 2), to = foo1)
49+
#' convert(Foo2(x = 1L, y = 2), to = Foo1)
5050
#'
5151
#' # Upcasting: S7 also provides a default implementation for coercing an object
5252
#' # to one of its child classes:
53-
#' convert(foo1(x = 1L), to = foo2)
54-
#' convert(foo1(x = 1L), to = foo2, y = 2.5) # Set new property
55-
#' convert(foo1(x = 1L), to = foo2, x = 2L, y = 2.5) # Override existing and set new
53+
#' convert(Foo1(x = 1L), to = Foo2)
54+
#' convert(Foo1(x = 1L), to = Foo2, y = 2.5) # Set new property
55+
#' convert(Foo1(x = 1L), to = Foo2, x = 2L, y = 2.5) # Override existing and set new
5656
#'
5757
#' # For all other cases, you'll need to provide your own.
58-
#' try(convert(foo1(x = 1L), to = class_integer))
58+
#' try(convert(Foo1(x = 1L), to = class_integer))
5959
#'
60-
#' method(convert, list(foo1, class_integer)) <- function(from, to) {
60+
#' method(convert, list(Foo1, class_integer)) <- function(from, to) {
6161
#' from@x
6262
#' }
63-
#' convert(foo1(x = 1L), to = class_integer)
63+
#' convert(Foo1(x = 1L), to = class_integer)
6464
#'
6565
#' # Note that conversion does not respect inheritance so if we define a
6666
#' # convert method for integer to foo1
67-
#' method(convert, list(class_integer, foo1)) <- function(from, to) {
68-
#' foo1(x = from)
67+
#' method(convert, list(class_integer, Foo1)) <- function(from, to) {
68+
#' Foo1(x = from)
6969
#' }
70-
#' convert(1L, to = foo1)
70+
#' convert(1L, to = Foo1)
7171
#'
72-
#' # Converting to foo2 will still error
73-
#' try(convert(1L, to = foo2))
72+
#' # Converting to Foo2 will still error
73+
#' try(convert(1L, to = Foo2))
7474
#' # This is probably not surprising because foo2 also needs some value
7575
#' # for `@y`, but it definitely makes dispatch for convert() special
7676
convert <- function(from, to, ...) {

R/data.R

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
#' invisibly.
1212
#' @export
1313
#' @examples
14-
#' text <- new_class("text", parent = class_character)
15-
#' y <- text(c(foo = "bar"))
14+
#' Text <- new_class("Text", parent = class_character)
15+
#' y <- Text(c(foo = "bar"))
1616
#' y
1717
#' S7_data(y)
1818
#'

R/external-generic.R

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@
2424
#' `S7_external_generic`.
2525
#' @export
2626
#' @examples
27-
#' my_class <- new_class("my_class")
27+
#' MyClass <- new_class("MyClass")
2828
#'
2929
#' your_generic <- new_external_generic("stats", "median", "x")
30-
#' method(your_generic, my_class) <- function(x) "Hi!"
30+
#' method(your_generic, MyClass) <- function(x) "Hi!"
3131
new_external_generic <- function(package, name, dispatch_args, version = NULL) {
3232
out <- list(
3333
package = package,

R/inherits.R

+7-7
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@
1212
#' * `check_is_S7()` returns nothing; it's called for its side-effects.
1313
#' @export
1414
#' @examples
15-
#' foo1 <- new_class("foo1")
16-
#' foo2 <- new_class("foo2")
15+
#' Foo1 <- new_class("Foo1")
16+
#' Foo2 <- new_class("Foo2")
1717
#'
18-
#' S7_inherits(foo1(), foo1)
19-
#' check_is_S7(foo1())
20-
#' check_is_S7(foo1(), foo1)
18+
#' S7_inherits(Foo1(), Foo1)
19+
#' check_is_S7(Foo1())
20+
#' check_is_S7(Foo1(), Foo1)
2121
#'
22-
#' S7_inherits(foo1(), foo2)
23-
#' try(check_is_S7(foo1(), foo2))
22+
#' S7_inherits(Foo1(), Foo2)
23+
#' try(check_is_S7(Foo1(), Foo2))
2424
S7_inherits <- function(x, class = NULL) {
2525
if (!(is.null(class) || inherits(class, "S7_class"))) {
2626
stop("`class` must be an <S7_class> or NULL")

R/method-introspect.R

+5-5
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,14 @@ method <- function(generic, class = NULL, object = NULL) {
6969
#' @return Nothing; this function is called for it's side effects.
7070
#' @export
7171
#' @examples
72-
#' foo1 <- new_class("foo1")
73-
#' foo2 <- new_class("foo2", foo1)
72+
#' Foo1 <- new_class("Foo1")
73+
#' Foo2 <- new_class("Foo2", Foo1)
7474
#'
7575
#' add <- new_generic("add", c("x", "y"))
76-
#' method(add, list(foo2, foo1)) <- function(x, y) c(2, 1)
77-
#' method(add, list(foo1, foo1)) <- function(x, y) c(1, 1)
76+
#' method(add, list(Foo2, Foo1)) <- function(x, y) c(2, 1)
77+
#' method(add, list(Foo1, Foo1)) <- function(x, y) c(1, 1)
7878
#'
79-
#' method_explain(add, list(foo2, foo2))
79+
#' method_explain(add, list(Foo2, Foo2))
8080
method_explain <- function(generic, class = NULL, object = NULL) {
8181
check_is_S7(generic, S7_generic)
8282
dispatch <- as_dispatch(generic, class = class, object = object)

R/property.R

+13-13
Original file line numberDiff line numberDiff line change
@@ -47,31 +47,31 @@
4747
#' @export
4848
#' @examples
4949
#' # Simple properties store data inside an object
50-
#' pizza <- new_class("pizza", properties = list(
50+
#' Pizza <- new_class("Pizza", properties = list(
5151
#' slices = new_property(class_numeric, default = 10)
5252
#' ))
53-
#' my_pizza <- pizza(slices = 6)
53+
#' my_pizza <- Pizza(slices = 6)
5454
#' my_pizza@slices
5555
#' my_pizza@slices <- 5
5656
#' my_pizza@slices
5757
#'
58-
#' your_pizza <- pizza()
58+
#' your_pizza <- Pizza()
5959
#' your_pizza@slices
6060
#'
6161
#' # Dynamic properties can compute on demand
62-
#' clock <- new_class("clock", properties = list(
62+
#' Clock <- new_class("Clock", properties = list(
6363
#' now = new_property(getter = function(self) Sys.time())
6464
#' ))
65-
#' my_clock <- clock()
65+
#' my_clock <- Clock()
6666
#' my_clock@now; Sys.sleep(1)
6767
#' my_clock@now
6868
#' # This property is read only, because there is a 'getter' but not a 'setter'
6969
#' try(my_clock@now <- 10)
7070
#'
7171
#' # Because the property is dynamic, it is not included as an
7272
#' # argument to the default constructor
73-
#' try(clock(now = 10))
74-
#' args(clock)
73+
#' try(Clock(now = 10))
74+
#' args(Clock)
7575
new_property <- function(class = class_any,
7676
getter = NULL,
7777
setter = NULL,
@@ -176,12 +176,12 @@ prop_default <- function(prop, envir, package) {
176176
#' the modified object, invisibly.
177177
#' @export
178178
#' @examples
179-
#' horse <- new_class("horse", properties = list(
179+
#' Horse <- new_class("Horse", properties = list(
180180
#' name = class_character,
181181
#' colour = class_character,
182182
#' height = class_numeric
183183
#' ))
184-
#' lexington <- horse(colour = "bay", height = 15, name = "Lex")
184+
#' lexington <- Horse(colour = "bay", height = 15, name = "Lex")
185185
#' lexington@colour
186186
#' prop(lexington, "colour")
187187
#'
@@ -352,8 +352,8 @@ prop_label <- function(object, name) {
352352
#' a single `TRUE` or `FALSE`.
353353
#' @export
354354
#' @examples
355-
#' foo <- new_class("foo", properties = list(a = class_character, b = class_integer))
356-
#' f <- foo()
355+
#' Foo <- new_class("Foo", properties = list(a = class_character, b = class_integer))
356+
#' f <- Foo()
357357
#'
358358
#' prop_names(f)
359359
#' prop_exists(f, "a")
@@ -404,12 +404,12 @@ prop_exists <- function(object, name) {
404404
#' @returns A named list of property values.
405405
#' @export
406406
#' @examples
407-
#' horse <- new_class("horse", properties = list(
407+
#' Horse <- new_class("Horse", properties = list(
408408
#' name = class_character,
409409
#' colour = class_character,
410410
#' height = class_numeric
411411
#' ))
412-
#' lexington <- horse(colour = "bay", height = 15, name = "Lex")
412+
#' lexington <- Horse(colour = "bay", height = 15, name = "Lex")
413413
#'
414414
#' props(lexington)
415415
#' props(lexington) <- list(height = 14, name = "Lexington")

R/super.R

+22-22
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,18 @@
2626
#' For example, imagine that you have made a subclass of "integer":
2727
#'
2828
#' ```{r}
29-
#' myint <- new_class("myint", parent = class_integer, package = NULL)
29+
#' MyInt <- new_class("MyInt", parent = class_integer, package = NULL)
3030
#' ```
3131
#'
3232
#' Now you go to write a custom print method:
3333
#'
3434
#' ```{r}
35-
#' method(print, myint) <- function(x, ...) {
36-
#' cat("<myint>")
35+
#' method(print, MyInt) <- function(x, ...) {
36+
#' cat("<MyInt>")
3737
#' print(super(x, to = class_integer))
3838
#' }
3939
#'
40-
#' myint(10L)
40+
#' MyInt(10L)
4141
#' ```
4242
#'
4343
#' This doesn't work because `print()` isn't an S7 generic so doesn't
@@ -47,12 +47,12 @@
4747
#' the underlying base object:
4848
#'
4949
#' ```{r}
50-
#' method(print, myint) <- function(x, ...) {
51-
#' cat("<myint>")
50+
#' method(print, MyInt) <- function(x, ...) {
51+
#' cat("<MyInt>")
5252
#' print(S7_data(x))
5353
#' }
5454
#'
55-
#' myint(10L)
55+
#' MyInt(10L)
5656
#' ```
5757
#'
5858
#' @param from An S7 object to cast.
@@ -62,41 +62,41 @@
6262
#' immediately to a generic. It has no other special behavior.
6363
#' @export
6464
#' @examples
65-
#' foo1 <- new_class("foo1", properties = list(x = class_numeric, y = class_numeric))
66-
#' foo2 <- new_class("foo2", foo1, properties = list(z = class_numeric))
65+
#' Foo1 <- new_class("Foo1", properties = list(x = class_numeric, y = class_numeric))
66+
#' Foo2 <- new_class("Foo2", Foo1, properties = list(z = class_numeric))
6767
#'
6868
#' total <- new_generic("total", "x")
69-
#' method(total, foo1) <- function(x) x@x + x@y
69+
#' method(total, Foo1) <- function(x) x@x + x@y
7070
#'
7171
#' # This won't work because it'll be stuck in an infinite loop:
72-
#' method(total, foo2) <- function(x) total(x) + x@z
72+
#' method(total, Foo2) <- function(x) total(x) + x@z
7373
#'
7474
#' # We could write
75-
#' method(total, foo2) <- function(x) x@x + x@y + x@z
75+
#' method(total, Foo2) <- function(x) x@x + x@y + x@z
7676
#' # but then we'd need to remember to update it if the implementation
77-
#' # for total(<foo1>) ever changed.
77+
#' # for total(<Foo1>) ever changed.
7878
#'
7979
#' # So instead we use `super()` to call the method for the parent class:
80-
#' method(total, foo2) <- function(x) total(super(x, to = foo1)) + x@z
81-
#' total(foo2(1, 2, 3))
80+
#' method(total, Foo2) <- function(x) total(super(x, to = Foo1)) + x@z
81+
#' total(Foo2(1, 2, 3))
8282
#'
8383
#' # To see the difference between convert() and super() we need a
8484
#' # method that calls another generic
8585
#'
8686
#' bar1 <- new_generic("bar1", "x")
87-
#' method(bar1, foo1) <- function(x) 1
88-
#' method(bar1, foo2) <- function(x) 2
87+
#' method(bar1, Foo1) <- function(x) 1
88+
#' method(bar1, Foo2) <- function(x) 2
8989
#'
9090
#' bar2 <- new_generic("bar2", "x")
91-
#' method(bar2, foo1) <- function(x) c(1, bar1(x))
92-
#' method(bar2, foo2) <- function(x) c(2, bar1(x))
91+
#' method(bar2, Foo1) <- function(x) c(1, bar1(x))
92+
#' method(bar2, Foo2) <- function(x) c(2, bar1(x))
9393
#'
94-
#' obj <- foo2(1, 2, 3)
94+
#' obj <- Foo2(1, 2, 3)
9595
#' bar2(obj)
9696
#' # convert() affects every generic:
97-
#' bar2(convert(obj, to = foo1))
97+
#' bar2(convert(obj, to = Foo1))
9898
#' # super() only affects the _next_ call to a generic:
99-
#' bar2(super(obj, to = foo1))
99+
#' bar2(super(obj, to = Foo1))
100100
super <- function(from, to) {
101101
check_is_S7(from)
102102

S7.Rproj

+2
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,5 @@ BuildType: Package
2020
PackageUseDevtools: Yes
2121
PackageInstallArgs: --no-multiarch --with-keep.source
2222
PackageRoxygenize: rd,collate,namespace
23+
24+
MarkdownWrap: Sentence

0 commit comments

Comments
 (0)