From aae74bca24c90866d452d3d8787ef5ef88b1c320 Mon Sep 17 00:00:00 2001 From: hadley Date: Wed, 29 Nov 2023 18:18:14 +0000 Subject: [PATCH] =?UTF-8?q?Deploying=20to=20gh-pages=20from=20@=20RConsort?= =?UTF-8?q?ium/S7@687c173fb6f5d3cd42f626f954f8caf9d29b4eac=20=F0=9F=9A=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- articles/S7.html | 2 +- articles/performance.html | 90 +++++++++++++++++------------------ pkgdown.yml | 2 +- reference/method.html | 6 +-- reference/new_property.html | 4 +- reference/super.html | 93 +++++++++++++++++++++++++++++++++++++ search.json | 2 +- 7 files changed, 146 insertions(+), 53 deletions(-) diff --git a/articles/S7.html b/articles/S7.html index 74581ca0..9669e113 100644 --- a/articles/S7.html +++ b/articles/S7.html @@ -319,7 +319,7 @@

Method dispatch and inheritance#> { #> paste0(x@name, " is ", x@age, " years old") #> } -#> <bytecode: 0x55ae6b07b170> +#> <bytecode: 0x55cbcf0f8e10>

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

diff --git a/articles/performance.html b/articles/performance.html index c37c1b87..11107efe 100644 --- a/articles/performance.html +++ b/articles/performance.html @@ -126,9 +126,9 @@ #> # 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) 9.45µs 10.54µs 91855. 21.3KB 36.8 -#> 2 foo_S3(x) 2.67µs 2.9µs 319070. 0B 31.9 -#> 3 foo_S4(x) 2.89µs 3.17µs 299597. 0B 30.0 +#> 1 foo_S7(x) 9.64µs 10.87µs 89058. 21.3KB 35.6 +#> 2 foo_S3(x) 2.62µs 2.9µs 317435. 0B 31.7 +#> 3 foo_S4(x) 2.83µs 3.23µs 291187. 0B 29.1 bar_S7 <- new_generic("bar_S7", c("x", "y")) method(bar_S7, list(text, number)) <- function(x, y, ...) paste0(x, "-", y, "-bar") @@ -142,8 +142,8 @@ #> # 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) 15.97µs 17.46µs 56061. 0B 33.7 -#> 2 bar_S4(x, y) 7.62µs 8.38µs 114064. 0B 22.8 +#> 1 bar_S7(x, y) 16.04µs 17.9µs 54507. 0B 32.7 +#> 2 bar_S4(x, y) 7.66µs 8.54µs 113832. 0B 22.8

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 @@ -202,26 +202,26 @@ #> # 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 9.47µs 10.7µs 91966. 0B 36.8 -#> 2 worst 3 15 9.63µs 10.6µs 93243. 0B 37.3 -#> 3 best 5 15 9.5µs 10.3µs 95394. 0B 38.2 -#> 4 worst 5 15 9.77µs 10.6µs 92466. 0B 37.0 -#> 5 best 10 15 9.5µs 10.6µs 90746. 0B 36.3 -#> 6 worst 10 15 10µs 11µs 88994. 0B 35.6 -#> 7 best 50 15 10.1µs 11.1µs 89057. 0B 35.6 -#> 8 worst 50 15 12.04µs 13.1µs 75607. 0B 30.3 -#> 9 best 100 15 10.65µs 11.7µs 84266. 0B 42.2 -#> 10 worst 100 15 14.48µs 15.5µs 62923. 0B 25.2 -#> 11 best 3 100 9.42µs 10.6µs 91495. 0B 45.8 -#> 12 worst 3 100 9.83µs 10.7µs 91211. 0B 36.5 -#> 13 best 5 100 9.6µs 10.5µs 92994. 0B 46.5 -#> 14 worst 5 100 10.11µs 10.9µs 89992. 0B 36.0 -#> 15 best 10 100 9.71µs 10.8µs 89907. 0B 36.0 -#> 16 worst 10 100 10.49µs 11.6µs 83697. 0B 41.9 -#> 17 best 50 100 10.16µs 11µs 88074. 0B 17.6 -#> 18 worst 50 100 14.91µs 15.7µs 62591. 0B 18.8 -#> 19 best 100 100 10.73µs 11.5µs 85743. 0B 25.7 -#> 20 worst 100 100 21.17µs 22.1µs 44732. 0B 8.95 +#> 1 best 3 15 9.61µs 11.2µs 87436. 0B 35.0 +#> 2 worst 3 15 9.89µs 11.4µs 85964. 0B 34.4 +#> 3 best 5 15 9.8µs 11.3µs 87023. 0B 34.8 +#> 4 worst 5 15 9.94µs 11.2µs 87268. 0B 34.9 +#> 5 best 10 15 9.67µs 11µs 88860. 0B 35.6 +#> 6 worst 10 15 10.28µs 11.5µs 84955. 0B 34.0 +#> 7 best 50 15 10.14µs 11.7µs 83179. 0B 33.3 +#> 8 worst 50 15 11.97µs 13.6µs 68638. 0B 27.5 +#> 9 best 100 15 10.93µs 12.5µs 78009. 0B 31.2 +#> 10 worst 100 15 14.75µs 16.1µs 60776. 0B 30.4 +#> 11 best 3 100 9.72µs 11.2µs 87143. 0B 34.9 +#> 12 worst 3 100 9.9µs 11.5µs 84944. 0B 42.5 +#> 13 best 5 100 9.66µs 10.8µs 89979. 0B 45.0 +#> 14 worst 5 100 10.09µs 11.3µs 86655. 0B 34.7 +#> 15 best 10 100 9.59µs 10.9µs 89848. 0B 44.9 +#> 16 worst 10 100 10.26µs 11.5µs 84003. 0B 33.6 +#> 17 best 50 100 10.17µs 11µs 86719. 0B 17.3 +#> 18 worst 50 100 15.63µs 16.7µs 58999. 0B 17.7 +#> 19 best 100 100 10.82µs 11.8µs 82791. 0B 16.6 +#> 20 worst 100 100 21.27µs 22.4µs 43803. 0B 13.1

And the same benchmark using double-dispatch

 bench::press(
@@ -262,26 +262,26 @@
 #> # 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     11µs     12µs    80964.        0B    24.3 
-#>  2 worst                3          15   11.6µs   12.6µs    77463.        0B    23.2 
-#>  3 best                 5          15   11.2µs   12.2µs    80355.        0B    24.1 
-#>  4 worst                5          15   11.8µs   12.7µs    77285.        0B    23.2 
-#>  5 best                10          15   11.4µs   12.4µs    79274.        0B    23.8 
-#>  6 worst               10          15   12.4µs   13.3µs    74200.        0B    22.3 
-#>  7 best                50          15   12.5µs   13.4µs    73314.        0B    22.0 
-#>  8 worst               50          15     16µs   17.1µs    57661.        0B    17.3 
-#>  9 best               100          15   13.7µs   14.7µs    66629.        0B    26.7 
-#> 10 worst              100          15   20.9µs     22µs    44912.        0B    13.5 
-#> 11 best                 3         100   11.4µs   12.6µs    77272.        0B    23.2 
-#> 12 worst                3         100   12.1µs   13.3µs    71924.        0B    21.6 
-#> 13 best                 5         100   11.5µs   12.6µs    77596.        0B    23.3 
-#> 14 worst                5         100   12.4µs   13.4µs    72832.        0B    21.9 
-#> 15 best                10         100   11.4µs   12.5µs    78217.        0B    15.6 
-#> 16 worst               10         100   13.4µs   14.5µs    67535.        0B    20.3 
-#> 17 best                50         100   12.3µs   13.6µs    71313.        0B    21.4 
-#> 18 worst               50         100   23.5µs   24.6µs    39922.        0B    12.0 
-#> 19 best               100         100   13.8µs   15.1µs    63494.        0B    19.1 
-#> 20 worst              100         100   32.4µs   33.7µs    29318.        0B     8.80
+#> 1 best 3 15 11.4µs 12.6µs 78267. 0B 23.5 +#> 2 worst 3 15 11.7µs 12.8µs 75299. 0B 22.6 +#> 3 best 5 15 11.4µs 12.7µs 76375. 0B 22.9 +#> 4 worst 5 15 11.7µs 13.4µs 71954. 0B 21.6 +#> 5 best 10 15 11.4µs 12.7µs 76287. 0B 22.9 +#> 6 worst 10 15 12.2µs 13.4µs 72972. 0B 21.9 +#> 7 best 50 15 12.1µs 13.5µs 71066. 0B 21.3 +#> 8 worst 50 15 15.7µs 17.1µs 57032. 0B 17.1 +#> 9 best 100 15 13.8µs 15µs 64744. 0B 19.4 +#> 10 worst 100 15 21.1µs 22.6µs 43014. 0B 17.2 +#> 11 best 3 100 11.6µs 13.1µs 72094. 0B 21.6 +#> 12 worst 3 100 12.4µs 13.9µs 69295. 0B 20.8 +#> 13 best 5 100 11.4µs 12.9µs 75130. 0B 22.5 +#> 14 worst 5 100 12.3µs 13.6µs 71424. 0B 21.4 +#> 15 best 10 100 11.6µs 13µs 74077. 0B 22.2 +#> 16 worst 10 100 13.7µs 15.1µs 64230. 0B 19.3 +#> 17 best 50 100 12.6µs 14.1µs 68175. 0B 20.5 +#> 18 worst 50 100 21.2µs 23.1µs 40576. 0B 12.2 +#> 19 best 100 100 14µs 15.5µs 62393. 0B 18.7 +#> 20 worst 100 100 33.9µs 35.9µs 26732. 0B 10.7 diff --git a/pkgdown.yml b/pkgdown.yml index 46740471..7e4469f6 100644 --- a/pkgdown.yml +++ b/pkgdown.yml @@ -18,7 +18,7 @@ articles: dispatch: spec/dispatch.html proposal: spec/proposal.html requirements: spec/requirements.html -last_built: 2023-11-27T19:48Z +last_built: 2023-11-29T18:17Z urls: reference: https://rconsortium.github.io/S7/reference article: https://rconsortium.github.io/S7/articles diff --git a/reference/method.html b/reference/method.html index 17011b92..eded001c 100644 --- a/reference/method.html +++ b/reference/method.html @@ -131,12 +131,12 @@

Examples#> <S7_method> method(bizarro, class_integer) #> function (x) #> rev(x) -#> <environment: 0x55a0aabe9a40> +#> <environment: 0x5561beb43308> method(bizarro, object = 1) #> <S7_method> method(bizarro, class_double) #> function (x) #> rev(x) -#> <environment: 0x55a0aabe9a40> +#> <environment: 0x5561beb43308> method(bizarro, class = class_factor) #> <S7_method> method(bizarro, new_S3_class("factor")) #> function (x) @@ -144,7 +144,7 @@

Examples#> levels(x) <- rev(levels(x)) #> x #> } -#> <environment: 0x55a0aabe9a40> +#> <environment: 0x5561beb43308> # errors if method not found try(method(bizarro, class = class_data.frame)) diff --git a/reference/new_property.html b/reference/new_property.html index 924f0a24..89f1bb90 100644 --- a/reference/new_property.html +++ b/reference/new_property.html @@ -166,9 +166,9 @@

Examples)) my_clock <- clock() my_clock@now; Sys.sleep(1) -#> [1] "2023-11-27 19:48:40 UTC" +#> [1] "2023-11-29 18:17:29 UTC" my_clock@now -#> [1] "2023-11-27 19:48:41 UTC" +#> [1] "2023-11-29 18:17:30 UTC" # This property is read only try(my_clock@now <- 10) #> Error : Can't set read-only property <clock>@now diff --git a/reference/super.html b/reference/super.html index 40705cdb..e4255ed1 100644 --- a/reference/super.html +++ b/reference/super.html @@ -18,6 +18,38 @@ This makes super() more verbose, but substantially easier to understand and reason about. + + +super() in S3 generics + + +Note that you can't use super() in methods for an S3 generic. +For example, imagine that you have made a subclass of "integer": +myint &lt;- new_class("myint", parent = class_integer) + +Now you go to write a custom print method: +method(print, myint) &lt;- function(x, ...) { + cat("&lt;myint&gt;") + print(super(x, to = class_integer)) +} + +myint(10L) +#&gt; &lt;myint&gt;super(&lt;myint&gt;, &lt;integer&gt;) + +This doesn't work because print() isn't an S7 generic so doesn't +understand how to interpret the special object that super() produces. +While you could resolve this problem with NextMethod() (because S7 is +implemented on top of S3), we instead recommend using S7_data() to extract +the underlying base object: +method(print, myint) &lt;- function(x, ...) { + cat("&lt;myint&gt;") + print(S7_data(x)) +} + +myint(10L) +#&gt; &lt;myint&gt;[1] 10 + + ">Force method dispatch to use a superclass — super • S7