From fd36e80b960fc07576bdff0bc5d7f36439462734 Mon Sep 17 00:00:00 2001 From: t-kalinowski Date: Mon, 4 Nov 2024 17:25:31 +0000 Subject: [PATCH] =?UTF-8?q?Deploying=20to=20gh-pages=20from=20@=20RConsort?= =?UTF-8?q?ium/S7@89ff0c7b884d12afeb023d4c67b61e2358ee09e3=20=F0=9F=9A=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- articles/S7.html | 66 +++++++-------- articles/classes-objects.html | 125 +++++++++++++++------------- articles/compatibility.html | 33 ++++---- articles/generics-methods.html | 26 +++--- articles/performance.html | 120 +++++++++++++------------- pkgdown.yml | 2 +- reference/S4_register.html | 8 +- reference/S7_class.html | 6 +- reference/S7_data.html | 8 +- reference/S7_inherits.html | 16 ++-- reference/convert.html | 42 +++++----- reference/method.html | 6 +- reference/method_explain.html | 34 ++++---- reference/new_S3_class.html | 2 +- reference/new_class.html | 26 +++--- reference/new_external_generic.html | 4 +- reference/new_property.html | 22 ++--- reference/prop.html | 4 +- reference/prop_names.html | 4 +- reference/props.html | 6 +- reference/super.html | 88 ++++++++++---------- search.json | 2 +- 22 files changed, 326 insertions(+), 324 deletions(-) diff --git a/articles/S7.html b/articles/S7.html index f4125e29..f46afaab 100644 --- a/articles/S7.html +++ b/articles/S7.html @@ -101,12 +101,12 @@

Classes and objects
-dog <- new_class("dog", properties = list(
+Dog <- new_class("Dog", properties = list(
   name = class_character,
   age = class_numeric
 ))
-dog
-#> <dog> class
+Dog
+#> <Dog> class
 #> @ parent     : <S7_object>
 #> @ constructor: function(name, age) {...}
 #> @ validator  : <NULL>
@@ -121,9 +121,9 @@ 

Classes and objects
-lola <- dog(name = "Lola", age = 11)
+lola <- Dog(name = "Lola", age = 11)
 lola
-#> <dog>
+#> <Dog>
 #>  @ name: chr "Lola"
 #>  @ age : num 11

Once you have an S7 object, you can get and set properties using @@ -136,12 +136,12 @@

Classes and objectsnew_class():

 lola@age <- "twelve"
-#> Error: <dog>@age must be <integer> or <double>, not <character>
+#> Error: <Dog>@age must be <integer> or <double>, not <character>

Given an object, you can retrieves its class S7_class():

 S7_class(lola)
-#> <dog> class
+#> <Dog> class
 #> @ parent     : <S7_object>
 #> @ constructor: function(name, age) {...}
 #> @ validator  : <NULL>
@@ -153,7 +153,7 @@ 

Classes and objectsvignette("compatibility").

 class(lola)
-#> [1] "dog"       "S7_object"
+#> [1] "Dog" "S7_object"

If you want to learn more about the details of S7 classes and objects, including validation methods and more details of properties, please see vignette("classes-objects").

@@ -180,7 +180,7 @@

Generics and methods
-method(speak, dog) <- function(x) {
+method(speak, Dog) <- function(x) {
   "Woof"
 }

Once the method is registered, the generic will use it when @@ -191,15 +191,15 @@

Generics and methods
-cat <- new_class("cat", properties = list(
+Cat <- new_class("Cat", properties = list(
   name = class_character,
   age = class_double
 ))
-method(speak, cat) <- function(x) {
+method(speak, Cat) <- function(x) {
   "Meow"
 }
 
-fluffy <- cat(name = "Fluffy", age = 5)
+fluffy <- Cat(name = "Fluffy", age = 5)
 speak(fluffy)
 #> [1] "Meow"

You get an error if you call the generic with a class that doesn’t @@ -215,7 +215,7 @@

Method dispatch and inheritance
-pet <- new_class("pet",
+Pet <- new_class("Pet",
   properties = list(
     name = class_character,
     age = class_numeric
@@ -224,20 +224,20 @@ 

Method dispatch and inheritanceThen use the parent argument to new_class:

-cat <- new_class("cat", parent = pet)
-dog <- new_class("dog", parent = pet)
+Cat <- new_class("Cat", parent = Pet)
+Dog <- new_class("Dog", parent = Pet)
 
-cat
-#> <cat> class
-#> @ parent     : <pet>
+Cat
+#> <Cat> class
+#> @ parent     : <Pet>
 #> @ constructor: function(name, age) {...}
 #> @ validator  : <NULL>
 #> @ properties :
 #>  $ name: <character>          
 #>  $ age : <integer> or <double>
-dog
-#> <dog> class
-#> @ parent     : <pet>
+Dog
+#> <Dog> class
+#> @ parent     : <Pet>
 #> @ constructor: function(name, age) {...}
 #> @ validator  : <NULL>
 #> @ properties :
@@ -246,8 +246,8 @@ 

Method dispatch and inheritanceBecause we have created new classes, we need to recreate the existing lola and fluffy objects:

+lola <- Dog(name = "Lola", age = 11) +fluffy <- Cat(name = "Fluffy", age = 5)

Method dispatch takes advantage of the hierarchy of parent classes: if a method is not defined for a class, it will try the method for the parent class, and so on until it finds a method or gives up with an @@ -255,7 +255,7 @@

Method dispatch and inheritance
 describe <- new_generic("describe", "x")
-method(describe, pet) <- function(x) {
+method(describe, Pet) <- function(x) {
   paste0(x@name, " is ", x@age, " years old")
 }
 describe(lola)
@@ -263,7 +263,7 @@ 

Method dispatch and inheritancedescribe(fluffy) #> [1] "Fluffy is 5 years old" -method(describe, dog) <- function(x) { +method(describe, Dog) <- function(x) { paste0(x@name, " is a ", x@age, " year old dog") } describe(lola) @@ -277,12 +277,12 @@

Method dispatch and inheritance "An S7 object" } -cocktail <- new_class("cocktail", +Cocktail <- new_class("Cocktail", properties = list( ingredients = class_character ) ) -martini <- cocktail(ingredients = c("gin", "vermouth")) +martini <- Cocktail(ingredients = c("gin", "vermouth")) describe(martini) #> [1] "An S7 object"

Printing a generic will show you which methods are currently @@ -290,19 +290,19 @@

Method dispatch and inheritance
 describe
 #> <S7_generic> describe(x, ...) with 3 methods:
-#> 1: method(describe, pet)
-#> 2: method(describe, dog)
-#> 3: method(describe, S7_object)

+#> 1: method(describe, Dog) +#> 2: method(describe, S7_object) +#> 3: method(describe, Pet)

And you can use method() to retrieve the implementation of one of those methods:

-method(describe, pet)
-#> <S7_method> method(describe, pet)
+method(describe, Pet)
+#> <S7_method> method(describe, Pet)
 #> function (x) 
 #> {
 #>     paste0(x@name, " is ", x@age, " years old")
 #> }
-#> <bytecode: 0x55a9ae807d90>
+#> <bytecode: 0x560c9340ee00>

Learn more about method dispatch in vignette("generics-methods").

diff --git a/articles/classes-objects.html b/articles/classes-objects.html index 1923e0fe..b99282a8 100644 --- a/articles/classes-objects.html +++ b/articles/classes-objects.html @@ -90,11 +90,12 @@

Validation

Basics

-

In the following example we create a range class that enforces that -@start and @end are single numbers, and that -@start is less than @end:

+

In the following example we create a Range class that +enforces that @start and @end are single +numbers, and that @start is less than +@end:

-range <- new_class("range",
+Range <- new_class("Range",
   properties = list(
     start = class_double,
     end = class_double
@@ -128,25 +129,25 @@ 

When is validation performed?
-x <- range(1, 2:3)
-#> Error: <range> object properties are invalid:
+x <- Range(1, 2:3)
+#> Error: <Range> object properties are invalid:
 #> - @end must be <double>, not <integer>
-x <- range(10, 1)
-#> Error: <range> object is invalid:
+x <- Range(10, 1)
+#> Error: <Range> object is invalid:
 #> - @end (1) must be greater than or equal to @start (10)
 
-x <- range(1, 10)
+x <- Range(1, 10)
 x@start <- 20
-#> Error: <range> object is invalid:
+#> Error: <Range> object is invalid:
 #> - @end (10) must be greater than or equal to @start (20)

You can also manually validate() an object if you use a low-level R function to bypass the usual checks and balances of @:

-x <- range(1, 2)
+x <- Range(1, 2)
 attr(x, "start") <- 3
 validate(x)
-#> Error: <range> object is invalid:
+#> Error: <Range> object is invalid:
 #> - @end (2) must be greater than or equal to @start (3)
@@ -160,15 +161,15 @@

Avoiding validationx@end <- x@end + shift x } -shift(range(1, 10), 1) -#> <range> +shift(Range(1, 10), 1) +#> <Range> #> @ start: num 2 #> @ end : num 11

There’s a problem if shift is larger than @end - @start:

-shift(range(1, 10), 10)
-#> Error: <range> object is invalid:
+shift(Range(1, 10), 10)
+#> Error: <Range> object is invalid:
 #> - @end (10) must be greater than or equal to @start (11)

While the end result of shift() will be valid, an intermediate state is not. The easiest way to resolve this problem is to @@ -181,8 +182,8 @@

Avoiding validation) x } -shift(range(1, 10), 10) -#> <range> +shift(Range(1, 10), 10) +#> <Range> #> @ start: num 11 #> @ end : num 20

The object is still validated, but it’s only validated once, after @@ -198,7 +199,7 @@

Propertiesnew_property(). For example, the property definition of range above is shorthand for:

-range <- new_class("range",
+Range <- new_class("Range",
   properties = list(
     start = new_property(class_double),
     end = new_property(class_double)
@@ -217,13 +218,13 @@ 

Validation
 prop_number <- new_property(
-  class = class_double, 
+  class = class_double,
   validator = function(value) {
     if (length(value) != 1L) "must be length 1"
   }
 )
 
-range <- new_class("range",
+Range <- new_class("Range",
   properties = list(
     start = prop_number,
     end = prop_number
@@ -239,12 +240,12 @@ 

Validation} ) -range(start = c(1.5, 3.5)) -#> Error: <range> object properties are invalid: +Range(start = c(1.5, 3.5)) +#> Error: <Range> object properties are invalid: #> - @start must be length 1 #> - @end must be length 1 -range(end = c(1.5, 3.5)) -#> Error: <range> object properties are invalid: +Range(end = c(1.5, 3.5)) +#> Error: <Range> object properties are invalid: #> - @start must be length 1 #> - @end must be length 1

Note that property validators shouldn’t include the name of the @@ -258,14 +259,14 @@

Default valuenew_class() create an class that can be constructed with no arguments:

-empty <- new_class("empty",
+Empty <- new_class("Empty",
   properties = list(
     x = class_double,
     y = class_character,
     z = class_logical
   ))
-empty()
-#> <empty>
+Empty()
+#> <Empty>
 #>  @ x: num(0) 
 #>  @ y: chr(0) 
 #>  @ z: logi(0)
@@ -273,38 +274,38 @@

Default value
-empty <- new_class("empty",
+Empty <- new_class("Empty",
   properties = list(
     x = new_property(class_numeric, default = 0),
     y = new_property(class_character, default = ""),
     z = new_property(class_logical, default = NA)
   )
 )
-empty()
-#> <empty>
+Empty()
+#> <Empty>
 #>  @ x: num 0
 #>  @ y: chr ""
 #>  @ z: logi NA

A quoted call becomes a standard function promise in the default constructor, evaluated at the time the object is constructed.

-stopwatch <- new_class("stopwatch", properties = list(
+Stopwatch <- new_class("Stopwatch", properties = list(
   start_time = new_property(
-    class = class_POSIXct,  
+    class = class_POSIXct,
     default = quote(Sys.time())
-  ), 
+  ),
   elapsed = new_property(
     getter = function(self) {
       difftime(Sys.time(), self@start_time, units = "secs")
     }
   )
 ))
-args(stopwatch)
+args(Stopwatch)
 #> function (start_time = Sys.time()) 
 #> NULL
-round(stopwatch()@elapsed)
+round(Stopwatch()@elapsed)
 #> Time difference of 0 secs
-round(stopwatch(Sys.time() - 1)@elapsed)
+round(Stopwatch(Sys.time() - 1)@elapsed)
 #> Time difference of 1 secs
@@ -316,7 +317,7 @@

Computed properties
-range <- new_class("range",
+Range <- new_class("Range",
   properties = list(
     start = class_double,
     end = class_double,
@@ -326,16 +327,16 @@ 

Computed properties) ) -x <- range(start = 1, end = 10) +x <- Range(start = 1, end = 10) x -#> <range> +#> <Range> #> @ start : num 1 #> @ end : num 10 #> @ length: num 9

Computed properties are read-only:

 x@length <- 20
-#> Error: Can't set read-only property <range>@length
+#> Error: Can't set read-only property <Range>@length

Dynamic properties @@ -348,7 +349,7 @@

Dynamic properties
-range <- new_class("range",
+Range <- new_class("Range",
   properties = list(
     start = class_double,
     end = class_double,
@@ -363,16 +364,16 @@ 

Dynamic properties) ) -x <- range(start = 1, end = 10) +x <- Range(start = 1, end = 10) x -#> <range> +#> <Range> #> @ start : num 1 #> @ end : num(0) #> @ length: num(0) x@length <- 5 x -#> <range> +#> <Range> #> @ start : num 1 #> @ end : num 6 #> @ length: num 5

@@ -418,11 +419,11 @@

Deprecated properties hadley <- Person(first_name = "Hadley") # no warning -hadley@firstName +hadley@firstName #> Warning: @firstName is deprecated; please use @first_name instead #> [1] "Hadley" -hadley@firstName <- "John" +hadley@firstName <- "John" #> Warning: @firstName is deprecated; please use @first_name instead hadley@first_name # no warning @@ -438,11 +439,14 @@

Required properties
 Person <- new_class("Person", properties = list(
- name = new_property(class_character, validator = function(value) {
-   if (length(value) != 1 || is.na(value) || value == "")
-     "must be a non-empty string"
- }))
-)
+ name = new_property(
+   class_character,
+   validator = function(value) {
+     if (length(value) != 1 || is.na(value) || value == "")
+       "must be a non-empty string"
+   }
+ )
+))
 
 try(Person())
 #> Error : <Person> object properties are invalid:
@@ -457,8 +461,9 @@ 

Required properties#> @ name: chr "Alice"

 Person <- new_class("Person", properties = list(
- name = new_property(class_character,
-                     default = quote(stop("@name is required")))
+ name = new_property(
+   class_character,
+   default = quote(stop("@name is required")))
 ))
 
 try(Person())
@@ -499,7 +504,7 @@ 

Constructors
-range@constructor
+Range@constructor
 #> function (start = numeric(0), end = numeric(0), length = numeric(0)) 
 #> {
 #>     start
@@ -514,20 +519,20 @@ 

Constructors
-range <- new_class("range",
+Range <- new_class("Range",
   properties = list(
     start = class_numeric,
     end = class_numeric
   ),
   constructor = function(x) {
-    new_object(S7_object(), start = min(x, na.rm = TRUE), end = max(x, na.rm = TRUE))
+    new_object(S7_object(), 
+               start = min(x, na.rm = TRUE), 
+               end = max(x, na.rm = TRUE))
   }
 )
 
 range(c(10, 5, 0, 2, 5, 7))
-#> <range>
-#>  @ start: num 0
-#>  @ end  : num 10

+#> [1] 0 10

A constructor must always end with a call to new_object(). The first argument to new_object() should be an object of the parent diff --git a/articles/compatibility.html b/articles/compatibility.html index 958f1b1a..95b78ff0 100644 --- a/articles/compatibility.html +++ b/articles/compatibility.html @@ -114,15 +114,15 @@

Methods
-foo <- new_class("foo")
-class(foo())
-#> [1] "foo"       "S7_object"
+Foo <- new_class("Foo")
+class(Foo())
+#> [1] "Foo"       "S7_object"
 
-mean.foo <- function(x, ...) {
+mean.Foo <- function(x, ...) {
   "mean of foo"
 }
 
-mean(foo())
+mean(Foo())
 #> [1] "mean of foo"
@@ -177,18 +177,18 @@

List classes
-new_rle <- new_class("rle", properties = list(
+rle <- new_class("rle", properties = list(
   lengths = class_integer,
   values = class_atomic
 ))

To allow existing methods to work you’ll need to override $ to access properties instead of list elements:

-method(`$`, new_rle) <- prop
+method(`$`, rle) <- prop
 rle(1:10)
 #> Run Length Encoding
-#>   lengths: int [1:10] 1 1 1 1 1 1 1 1 1 1
-#>   values : int [1:10] 1 2 3 4 5 6 7 8 9 10
+#> lengths: int [1:10] 1 2 3 4 5 6 7 8 9 10 +#> values : logi(0)

The chief disadvantage of this approach is any subclasses will need to be converted to S7 as well.

@@ -220,22 +220,19 @@

Unions union is just short-hand for registering a method for each of the classes.

-class1 <- new_class("class1")
-class2 <- new_class("class2")
-union1 <- new_union(class1, class2)
+Class1 <- new_class("Class1")
+Class2 <- new_class("Class2")
+Union1 <- new_union(Class1, Class2)
 
 foo <- new_generic("foo", "x")
-method(foo, union1) <- function(x) ""
+method(foo, Union1) <- function(x) ""
 foo
 #> <S7_generic> foo(x, ...) with 2 methods:
-#> 1: method(foo, class1)
-#> 2: method(foo, class2)
+#> 1: method(foo, Class2) +#> 2: method(foo, Class1)

S7 unions allow you to restrict the type of a property in the same way that S4 unions allow you to restrict the type of a slot.

- -
-

diff --git a/articles/generics-methods.html b/articles/generics-methods.html index 731a8774..6031edab 100644 --- a/articles/generics-methods.html +++ b/articles/generics-methods.html @@ -350,27 +350,27 @@

A simple exampleLet’s take our speak example from vignette("S7") and extend it to teach our pets how to speak multiple languages:

-pet <- new_class("pet")
-dog <- new_class("dog", pet)
-cat <- new_class("cat", pet)
+Pet <- new_class("Pet")
+Dog <- new_class("Dog", Pet)
+Cat <- new_class("Cat", Pet)
 
-language <- new_class("language")
-english <- new_class("english", language)
-french <- new_class("french", language)
+Language <- new_class("Language")
+English <- new_class("English", Language)
+French <- new_class("French", Language)
 
 speak <- new_generic("speak", c("x", "y"))
-method(speak, list(dog, english)) <- function(x, y) "Woof"
-method(speak, list(cat, english)) <- function(x, y) "Meow"
-method(speak, list(dog, french)) <- function(x, y) "Ouaf Ouaf"
-method(speak, list(cat, french)) <- function(x, y) "Miaou"
+method(speak, list(Dog, English)) <- function(x, y) "Woof"
+method(speak, list(Cat, English)) <- function(x, y) "Meow"
+method(speak, list(Dog, French)) <- function(x, y) "Ouaf Ouaf"
+method(speak, list(Cat, French)) <- function(x, y) "Miaou"
 
-speak(cat(), english())
+speak(Cat(), English())
 #> [1] "Meow"
-speak(dog(), french())
+speak(Dog(), French())
 #> [1] "Ouaf Ouaf"
 
 # This example was originally inspired by blog.klipse.tech/javascript/2021/10/03/multimethod.html
-# which has unfortunately since disappeaed.
+# which has unfortunately since disappeared.

Special “classes” diff --git a/articles/performance.html b/articles/performance.html index 7b95b540..3d86d8de 100644 --- a/articles/performance.html +++ b/articles/performance.html @@ -79,54 +79,54 @@

Performance

though as this is implemented in a package there is some overhead due to .Call vs .Primitive.

-text <- new_class("text", parent = class_character)
-number <- new_class("number", parent = class_double)
+Text <- new_class("Text", parent = class_character)
+Number <- new_class("Number", parent = class_double)
 
-x <- text("hi")
-y <- number(1)
+x <- Text("hi")
+y <- Number(1)
 
 foo_S7 <- new_generic("foo_S7", "x")
-method(foo_S7, text) <- function(x, ...) paste0(x, "-foo")
+method(foo_S7, Text) <- function(x, ...) paste0(x, "-foo")
 
 foo_S3 <- function(x, ...) {
   UseMethod("foo_S3")
 }
 
-foo_S3.text <- function(x, ...) {
+foo_S3.Text <- function(x, ...) {
   paste0(x, "-foo")
 }
 
 library(methods)
-setOldClass(c("number", "numeric", "S7_object"))
-setOldClass(c("text", "character", "S7_object"))
+setOldClass(c("Number", "numeric", "S7_object"))
+setOldClass(c("Text", "character", "S7_object"))
 
 setGeneric("foo_S4", function(x, ...) standardGeneric("foo_S4"))
 #> [1] "foo_S4"
-setMethod("foo_S4", c("text"), function(x, ...) paste0(x, "-foo"))
+setMethod("foo_S4", c("Text"), function(x, ...) paste0(x, "-foo"))
 
 # Measure performance of single dispatch
 bench::mark(foo_S7(x), foo_S3(x), foo_S4(x))
 #> # A tibble: 3 × 6
 #>   expression      min   median `itr/sec` mem_alloc `gc/sec`
 #>   <bch:expr> <bch:tm> <bch:tm>     <dbl> <bch:byt>    <dbl>
-#> 1 foo_S7(x)    7.05µs   8.04µs   117446.    18.2KB     23.5
-#> 2 foo_S3(x)    2.62µs   2.86µs   323546.        0B     32.4
-#> 3 foo_S4(x)    2.83µs   3.23µs   302811.        0B      0
+#> 1 foo_S7(x)     7.4µs   8.52µs   111052.    18.2KB     22.2
+#> 2 foo_S3(x)    2.62µs   2.89µs   322831.        0B     32.3
+#> 3 foo_S4(x)    2.79µs   3.25µs   300889.        0B      0
 
 bar_S7 <- new_generic("bar_S7", c("x", "y"))
-method(bar_S7, list(text, number)) <- function(x, y, ...) paste0(x, "-", y, "-bar")
+method(bar_S7, list(Text, Number)) <- function(x, y, ...) paste0(x, "-", y, "-bar")
 
 setGeneric("bar_S4", function(x, y, ...) standardGeneric("bar_S4"))
 #> [1] "bar_S4"
-setMethod("bar_S4", c("text", "number"), function(x, y, ...) paste0(x, "-", y, "-bar"))
+setMethod("bar_S4", c("Text", "Number"), function(x, y, ...) paste0(x, "-", y, "-bar"))
 
 # Measure performance of double dispatch
 bench::mark(bar_S7(x, y), bar_S4(x, y))
 #> # A tibble: 2 × 6
 #>   expression        min   median `itr/sec` mem_alloc `gc/sec`
 #>   <bch:expr>   <bch:tm> <bch:tm>     <dbl> <bch:byt>    <dbl>
-#> 1 bar_S7(x, y)  13.75µs  15.14µs    64536.        0B     25.8
-#> 2 bar_S4(x, y)   8.05µs   8.84µs   110836.        0B     11.1
+#> 1 bar_S7(x, y) 13.91µs 15.26µs 64149. 0B 25.7 +#> 2 bar_S4(x, y) 7.86µs 8.75µs 112749. 0B 11.3

A potential optimization is caching based on the class names, but lookup should be fast without this.

The following benchmark generates a class hierarchy of different @@ -153,8 +153,8 @@

Performance

class_nchar = c(15, 100), { # Construct a class hierarchy with that number of classes - text <- new_class("text", parent = class_character) - parent <- text + Text <- new_class("Text", parent = class_character) + parent <- Text classes <- gen_character(num_classes, min = class_nchar, max = class_nchar) env <- new.env() for (x in classes) { @@ -185,26 +185,26 @@

Performance

#> # A tibble: 20 × 8 #> expression num_classes class_nchar min median `itr/sec` mem_alloc `gc/sec` #> <bch:expr> <dbl> <dbl> <bch:tm> <bch:tm> <dbl> <bch:byt> <dbl> -#> 1 best 3 15 6.89µs 8.21µs 118685. 0B 35.6 -#> 2 worst 3 15 7.32µs 8.55µs 114445. 0B 34.3 -#> 3 best 5 15 7.21µs 8.36µs 116375. 0B 34.9 -#> 4 worst 5 15 7.51µs 8.71µs 112152. 0B 33.7 -#> 5 best 10 15 7.27µs 8.56µs 114069. 0B 22.8 -#> 6 worst 10 15 7.63µs 8.86µs 110443. 0B 33.1 -#> 7 best 50 15 7.86µs 9.12µs 107092. 0B 32.1 -#> 8 worst 50 15 9.54µs 10.86µs 89364. 0B 26.8 -#> 9 best 100 15 8.39µs 9.55µs 102775. 0B 30.8 -#> 10 worst 100 15 11.91µs 12.88µs 76428. 0B 30.6 -#> 11 best 3 100 7.37µs 8.53µs 114788. 0B 34.4 -#> 12 worst 3 100 7.65µs 8.88µs 109877. 0B 33.0 -#> 13 best 5 100 7.29µs 8.4µs 116337. 0B 34.9 -#> 14 worst 5 100 7.73µs 8.75µs 111549. 0B 33.5 -#> 15 best 10 100 7.3µs 8.47µs 114158. 0B 34.3 -#> 16 worst 10 100 8.06µs 9.13µs 106703. 0B 32.0 -#> 17 best 50 100 7.92µs 9.07µs 107631. 0B 32.3 -#> 18 worst 50 100 12.89µs 14.05µs 69884. 0B 21.0 -#> 19 best 100 100 8.43µs 9.72µs 100289. 0B 40.1 -#> 20 worst 100 100 19.13µs 20.49µs 47780. 0B 14.3
+#> 1 best 3 15 7.07µs 8.35µs 117653. 0B 35.3 +#> 2 worst 3 15 7.29µs 8.5µs 114896. 0B 34.5 +#> 3 best 5 15 7.17µs 8.45µs 115986. 0B 34.8 +#> 4 worst 5 15 7.51µs 8.67µs 113197. 0B 34.0 +#> 5 best 10 15 7.26µs 8.52µs 115160. 0B 23.0 +#> 6 worst 10 15 7.72µs 8.96µs 109542. 0B 32.9 +#> 7 best 50 15 7.76µs 9.03µs 108284. 0B 32.5 +#> 8 worst 50 15 9.38µs 10.73µs 91457. 0B 27.4 +#> 9 best 100 15 8.37µs 9.73µs 100560. 0B 30.2 +#> 10 worst 100 15 11.9µs 13.23µs 74043. 0B 29.6 +#> 11 best 3 100 7.2µs 8.46µs 114998. 0B 34.5 +#> 12 worst 3 100 7.63µs 8.87µs 110376. 0B 33.1 +#> 13 best 5 100 7.37µs 8.6µs 113908. 0B 34.2 +#> 14 worst 5 100 7.57µs 8.91µs 109216. 0B 32.8 +#> 15 best 10 100 7.33µs 8.71µs 111095. 0B 33.3 +#> 16 worst 10 100 8.03µs 9.3µs 104547. 0B 31.4 +#> 17 best 50 100 7.68µs 9µs 107842. 0B 32.4 +#> 18 worst 50 100 12.74µs 14.17µs 68976. 0B 20.7 +#> 19 best 100 100 8.44µs 9.97µs 96803. 0B 38.7 +#> 20 worst 100 100 19.07µs 20.5µs 47929. 0B 14.4

And the same benchmark using double-dispatch

 bench::press(
@@ -212,8 +212,8 @@ 

Performance

class_nchar = c(15, 100), { # Construct a class hierarchy with that number of classes - text <- new_class("text", parent = class_character) - parent <- text + Text <- new_class("Text", parent = class_character) + parent <- Text classes <- gen_character(num_classes, min = class_nchar, max = class_nchar) env <- new.env() for (x in classes) { @@ -245,26 +245,26 @@

Performance

#> # A tibble: 20 × 8 #> expression num_classes class_nchar min median `itr/sec` mem_alloc `gc/sec` #> <bch:expr> <dbl> <dbl> <bch:tm> <bch:tm> <dbl> <bch:byt> <dbl> -#> 1 best 3 15 8.91µs 10.3µs 93523. 0B 37.4 -#> 2 worst 3 15 9.25µs 10.3µs 93177. 0B 37.3 -#> 3 best 5 15 9.02µs 10.6µs 90567. 0B 27.2 -#> 4 worst 5 15 9.54µs 11µs 87073. 0B 34.8 -#> 5 best 10 15 9µs 10.4µs 92136. 0B 36.9 -#> 6 worst 10 15 9.78µs 10.4µs 94413. 0B 28.3 -#> 7 best 50 15 9.72µs 10.3µs 96145. 0B 28.9 -#> 8 worst 50 15 13.13µs 13.7µs 71789. 0B 28.7 -#> 9 best 100 15 11.07µs 11.7µs 83977. 0B 33.6 -#> 10 worst 100 15 17.92µs 19.1µs 51212. 0B 20.5 -#> 11 best 3 100 9.02µs 10µs 95841. 0B 28.8 -#> 12 worst 3 100 9.86µs 10.8µs 89495. 0B 35.8 -#> 13 best 5 100 8.94µs 10.1µs 95561. 0B 38.2 -#> 14 worst 5 100 10.06µs 11.2µs 87030. 0B 26.1 -#> 15 best 10 100 9.11µs 10.2µs 95093. 0B 38.1 -#> 16 worst 10 100 11.2µs 12.2µs 79619. 0B 31.9 -#> 17 best 50 100 10.17µs 11.4µs 79925. 0B 24.0 -#> 18 worst 50 100 19.36µs 21.6µs 39668. 0B 15.9 -#> 19 best 100 100 11.31µs 12.5µs 77228. 0B 30.9 -#> 20 worst 100 100 30.47µs 32.1µs 30461. 0B 12.2
+#> 1 best 3 15 8.91µs 10.3µs 92550. 0B 37.0 +#> 2 worst 3 15 9.22µs 10.7µs 90313. 0B 36.1 +#> 3 best 5 15 8.81µs 10.2µs 94441. 0B 28.3 +#> 4 worst 5 15 9.45µs 10.8µs 89332. 0B 35.7 +#> 5 best 10 15 8.98µs 10.3µs 93780. 0B 37.5 +#> 6 worst 10 15 9.71µs 10.4µs 94835. 0B 28.5 +#> 7 best 50 15 9.76µs 10.6µs 91177. 0B 27.4 +#> 8 worst 50 15 13.34µs 14.1µs 70187. 0B 28.1 +#> 9 best 100 15 11.03µs 11.8µs 82744. 0B 33.1 +#> 10 worst 100 15 18.1µs 19.5µs 50006. 0B 20.0 +#> 11 best 3 100 9.25µs 10.4µs 93406. 0B 28.0 +#> 12 worst 3 100 9.88µs 11.1µs 87383. 0B 35.0 +#> 13 best 5 100 8.96µs 10.2µs 94585. 0B 37.8 +#> 14 worst 5 100 9.89µs 11.1µs 87949. 0B 26.4 +#> 15 best 10 100 9.13µs 10.3µs 94166. 0B 37.7 +#> 16 worst 10 100 11.25µs 12.5µs 77994. 0B 31.2 +#> 17 best 50 100 10.25µs 11.5µs 84537. 0B 25.4 +#> 18 worst 50 100 19.33µs 20.6µs 47290. 0B 18.9 +#> 19 best 100 100 11.23µs 12.5µs 77490. 0B 31.0 +#> 20 worst 100 100 30.47µs 32µs 30751. 0B 12.3 diff --git a/pkgdown.yml b/pkgdown.yml index 0a46a68c..88c40472 100644 --- a/pkgdown.yml +++ b/pkgdown.yml @@ -18,7 +18,7 @@ articles: spec/proposal: spec/proposal.html spec/requirements: spec/requirements.html S7: S7.html -last_built: 2024-11-04T17:22Z +last_built: 2024-11-04T17:24Z urls: reference: https://rconsortium.github.io/S7/reference article: https://rconsortium.github.io/S7/articles diff --git a/reference/S4_register.html b/reference/S4_register.html index 0dca3eef..3ce79399 100644 --- a/reference/S4_register.html +++ b/reference/S4_register.html @@ -81,11 +81,11 @@

Examples}) #> [1] "S4_generic" -foo <- new_class("foo") -S4_register(foo) -method(S4_generic, foo) <- function(x) "Hello" +Foo <- new_class("Foo") +S4_register(Foo) +method(S4_generic, Foo) <- function(x) "Hello" -S4_generic(foo()) +S4_generic(Foo()) #> [1] "Hello" diff --git a/reference/S7_class.html b/reference/S7_class.html index a4bccad9..1c8b112d 100644 --- a/reference/S7_class.html +++ b/reference/S7_class.html @@ -69,9 +69,9 @@

Value

Examples

-
foo <- new_class("foo")
-S7_class(foo())
-#> <foo> class
+    
Foo <- new_class("Foo")
+S7_class(Foo())
+#> <Foo> class
 #> @ parent     : <S7_object>
 #> @ constructor: function() {...}
 #> @ validator  : <NULL>
diff --git a/reference/S7_data.html b/reference/S7_data.html
index b4c0bf4c..8a37108e 100644
--- a/reference/S7_data.html
+++ b/reference/S7_data.html
@@ -88,10 +88,10 @@ 

Value

Examples

-
text <- new_class("text", parent = class_character)
-y <- text(c(foo = "bar"))
+    
Text <- new_class("Text", parent = class_character)
+y <- Text(c(foo = "bar"))
 y
-#> <text> Named chr "bar"
+#> <Text> Named chr "bar"
 #>  - attr(*, "names")= chr "foo"
 S7_data(y)
 #>   foo 
@@ -99,7 +99,7 @@ 

Examples S7_data(y) <- c("a", "b") y -#> <text> Named chr [1:2] "a" "b" +#> <Text> Named chr [1:2] "a" "b" #> - attr(*, "names")= chr [1:2] "foo" NA

diff --git a/reference/S7_inherits.html b/reference/S7_inherits.html index a2f8b536..be5e23a3 100644 --- a/reference/S7_inherits.html +++ b/reference/S7_inherits.html @@ -94,18 +94,18 @@

Value

Examples

-
foo1 <- new_class("foo1")
-foo2 <- new_class("foo2")
+    
Foo1 <- new_class("Foo1")
+Foo2 <- new_class("Foo2")
 
-S7_inherits(foo1(), foo1)
+S7_inherits(Foo1(), Foo1)
 #> [1] TRUE
-check_is_S7(foo1())
-check_is_S7(foo1(), foo1)
+check_is_S7(Foo1())
+check_is_S7(Foo1(), Foo1)
 
-S7_inherits(foo1(), foo2)
+S7_inherits(Foo1(), Foo2)
 #> [1] FALSE
-try(check_is_S7(foo1(), foo2))
-#> Error : `foo1()` must be a <foo2>, not a <foo1>
+try(check_is_S7(Foo1(), Foo2))
+#> Error : `Foo1()` must be a <Foo2>, not a <Foo1>