Repository navigation
Conversation
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd4HRcA4823NuBCC8TS
The record under experiments/2026-11-29-s7/ tests S7 1.0.0 base classes and S7 generics against installed S4 backends (RSQLite, duckdb, a minimal backend). It also tests whether S7 properties avoid the class caching that makes #794 read its slot with attr(). S7 base classes registered with S4 keep installed backends working, but give #794 nothing: backends see S4 classes, and new properties reach only reinstalled backends. S7 generics break installed backends that define methods. The scripts and their recorded output sit beside the record, and .Rbuildignore now excludes experiments/. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd4HRcA4823NuBCC8TS
Superseded: Drop the idea of moving DBI's classes or generics to S7?Superseded by a question that takes the vendored S7 record into account: #795 (comment) The experiment record (R 4.5.3, S7 1.0.0) finds:
Kirill decides. If nobody decides, the idea is dropped and DBI stays on S4. Generated by Claude Code |
Superseded: Report the two S7 problems upstream?Superseded by a question that takes the vendored S7 record into account: #795 (comment) The experiment record found two behaviors of S7 1.0.0 that look like bugs: for an S4 subclass of an abstract S7 class,
Kirill decides; nothing is posted without his go-ahead. If nobody decides, nothing is reported. Generated by Claude Code |
Question: Merge the experiment record, or close this PR as a record only?This PR adds
Kirill decides. If nobody decides, the PR stays open as a draft and is not merged. Generated by Claude Code |
The record no longer says every installed backend fails to load with S7 generics: only RSQLite was reached, and the minimal backend loads but finds no method. Also name the variant where `dbConnect()` fails, give the real reason `attr()` stays necessary, add the fetch and the preinstalled packages to the replication steps, and default `WORK` to a neutral temporary directory. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd4HRcA4823NuBCC8TS
Clean review, round 1 (at cf332c3)Reviewed by an agent without context from the work, by re-running the record's scripts and checking its facts. No High findings; every claim re-run reproduced, and the conclusion (S7 does not simplify #794; Medium, both fixed in 06b3891:
Low, fixed in 06b3891: " Reproduced: Facts checked: versions; S7 requires Not checked: the Generated by Claude Code |
…ectory Say which variants the `.dbi` result holds for, and treat an empty `TMPDIR` in the R scripts as the shell scripts do. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd4HRcA4823NuBCC8TS
Clean review, rounds 2 and 3 (06b3891, 4b56685)
Generated by Claude Code |
Superseded: Accepted limitationsSuperseded by the current copy.
Generated by Claude Code |
|
Run another experiment with a vendored version of S7, adapted to fix the limitations and to make the move viable without having to upgrade all backends at the same time. Post issue drafts for the S7 repo as individual comments here. |
Adds the experiment record `experiments/2026-11-29-s7-vendored/`. It vendors S7 1.0.0 under its MIT license, with the changes in `S7.diff`: `prop()`, S7 dispatch and `S7_inherits()` work on S4 subclasses of abstract S7 classes, `S4_register()` accepts a concrete child of a registered abstract class, S7 dispatch on S4 objects caches the dispatch vector, and a new `S4_generic()` makes an S7 generic available as an S4 generic. With it, a DBI variant with S7 base classes and S7 generics for `dbConnect()`, `dbDisconnect()` and `dbGetQuery()` keeps the RSQLite and duckdb binaries and a minimal S4 backend working without reinstalling, alongside a minimal S7 backend. The record also holds issue drafts for S7, not posted. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd6RgjpQxckjWTEReje
Clean review of the vendored S7 record, round 1 (5dc085b)Scope: Medium
Low, all being fixed:
Reproduced: Checked and correct: the patches only change paths where CRAN S7 errored or that Not checked: that the binaries were built against DBI 1.3.0 (only the installed DBI 1.3.0 was seen); Generated by Claude Code |
…red S7 record States that the adapted S7 now stores methods for a registered abstract class and for its S4 class from `methods::getClass()` under one key, that no tests cover the changes to S7, and that the `dbGetQuery()` timings are from one run. Drops `Repository: CRAN` from the adapted copy's DESCRIPTION and says it is not a release of S7, redacts the default R library path in the recorded output, and clarifies the prop() hang draft, linking the loop in S7's source. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd6RgjpQxckjWTEReje
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd6RgjpQxckjWTEReje
Clean review of the vendored S7 record, round 2 (5dc085b..85573f7)Scope: the fixes of round 1. No High or Medium findings, so the review stops here. Low, all being fixed:
Checked and correct: the Medium of round 1 re-run (CRAN S7 stores keys Not checked: a fresh run of Generated by Claude Code |
…ed S7 Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd6RgjpQxckjWTEReje
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hr1rd6RgjpQxckjWTEReje
Issue draft 1 of 6 for the S7 repository (not posted there)Source:
|
Issue draft 2 of 6 for the S7 repository (not posted there)Source: S7 dispatch does not find methods for an abstract S7 class from an S4 subclass of itAn S7 method registered for an S7 class is not found for an object of an S4 class that extends that S7 class through ReprexWith S7 1.0.0 from CRAN: library(S7)
packageVersion("S7")
#> [1] '1.0.0'
Base <- new_class("Base", abstract = TRUE)
S4_register(Base)
methods::setClass("Child4", contains = "Base")
x <- methods::new("Child4")
describe <- new_generic("describe", "x")
method(describe, Base) <- function(x) "method for Base"
describe(x)
#> Error:
#> ! Can't find method for `describe(S4<Child4>)`.
## Expected: "method for Base"
## S4 sees the inheritance:
methods::is(x, "Base")
#> [1] TRUE
## S7 looks for a method under the S4 name of the registered class,
## but the method is registered under the S7 name:
method_explain(describe, object = x)
#> describe([S4/Child4])
#> describe([S4/Base])
#> describe([ANY])Expected and actualExpected: CauseFor an S4 object, Proposed fixIn @@ S4_class_name()
+# The S7 class that `x`, an S4 class definition, was registered for, or NULL.
+# S4_register_class() stores the S7 class in the prototype's `_S7_class` slot;
+# S4 subclasses inherit that prototype, so the names must match too.
+S4_registered_S7_class <- function(x) {
+ S7_class <- .Call(S7_class_, x@prototype)
+ if (
+ is_class(S7_class) &&
+ identical(S7_class_name(S7_class), as.character(x@className))
+ ) {
+ S7_class
+ }
+}
+
S4_class_name <- function(x) {
+ # An S4 class that S4_register() created for an S7 class stands for that
+ # S7 class: S4 subclasses then find methods registered for the S7 parent.
+ S7_class <- S4_registered_S7_class(x)
+ if (!is.null(S7_class)) {
+ return(S7_class_name(S7_class))
+ }
+
if (is_oldClass(x)) {This matters for a package that moves its base classes to abstract S7 classes while other, already installed packages extend them with Found while investigating a move of DBI's classes and generics from S4 to S7, in #795. The experiment record with the adapted S7 and the complete patch is at https://github.com/r-dbi/DBI/tree/ca42bd8ff5d03616d78499f22eccd6799bc1a8b8/experiments/2026-11-29-s7-vendored. Generated by Claude Code |
Issue draft 3 of 6 for the S7 repository (not posted there)Source:
|
Issue draft 4 of 6 for the S7 repository (not posted there)Source:
|
Issue draft 5 of 6 for the S7 repository (not posted there)Source: S7 dispatch on S4 objects is more than ten times slower than on S7 objectsDispatching an S7 generic on an S4 object takes tens of microseconds per call, more than ten times the cost on an S7 object and 60 to 125 times the cost of an S4 generic on the same object, in the runs below. Almost all of it goes into computing the dispatch vector of the S4 class, which is the same on every call. ReprexWith S7 1.0.0 from CRAN (timings vary between runs and machines): library(S7)
packageVersion("S7")
#> [1] '1.0.0'
methods::setClass("Obj4", slots = c(x = "numeric"))
Obj7 <- new_class("Obj7", properties = list(x = class_numeric))
methods::setGeneric("f4", function(x) standardGeneric("f4"))
#> [1] "f4"
methods::setMethod("f4", "Obj4", function(x) 1)
f7 <- new_generic("f7", "x")
method(f7, methods::getClass("Obj4")) <- function(x) 1
method(f7, Obj7) <- function(x) 1
o4 <- methods::new("Obj4", x = 1)
o7 <- Obj7(x = 1)
bench::mark(
`S4 generic, S4 object` = f4(o4),
`S7 generic, S4 object` = f7(o4),
`S7 generic, S7 object` = f7(o7),
min_iterations = 10000
)[, c("expression", "min", "median")]
#> # A tibble: 3 × 3
#> expression min median
#> <bch:expr> <bch:tm> <bch:tm>
#> 1 S4 generic, S4 object 597.91ns 884.06ns
#> 2 S7 generic, S4 object 40.45µs 58.98µs
#> 3 S7 generic, S7 object 3.14µs 4.74µs
## Expected: S7 dispatch on an S4 object about as fast as on an S7 object
## Most of the time goes into computing the dispatch vector of the S4 class,
## which is the same for every call:
bench::mark(S7:::obj_dispatch(o4), min_iterations = 10000)[, c(
"expression",
"median"
)]
#> # A tibble: 1 × 2
#> expression median
#> <bch:expr> <bch:tm>
#> 1 S7:::obj_dispatch(o4) 59.9µsExpected and actualExpected: S7 dispatch on an S4 object costs about as much as on an S7 object. Actual: 59 µs against 4.7 µs in the run above; 106 µs against 4.4 µs in the benchmark of the experiment record linked below. CauseFor an S4 object, Proposed fixCache the dispatch vector per S4 class, keyed by package and class name, and use a cache entry only while +S4_dispatch_cache <- new.env(hash = TRUE, parent = emptyenv())
+
+S4_obj_dispatch <- function(x) {
+ class <- class(x)
+ def <- methods::getClassDef(class)
+ if (is.null(def)) {
+ return(S4_class_dispatch(methods::getClass(class)))
+ }
+ key <- paste0(def@package, "::", def@className)
+ hit <- S4_dispatch_cache[[key]]
+ if (!is.null(hit) && identical(hit[[1L]], def)) {
+ return(hit[[2L]])
+ }
+ dispatch <- S4_class_dispatch(def)
+ S4_dispatch_cache[[key]] <- list(def, dispatch)
+ dispatch
+}and in - S4 = S4_class_dispatch(methods::getClass(class(x))),
+ S4 = S4_obj_dispatch(x),What the cache does not notice: a superclass redefined without redefining the subclass. Moving the computation to C, or hooking into the class cache of methods, could bring the cost down further. Found while investigating a move of DBI's classes and generics from S4 to S7, in #795. The experiment record with the adapted S7 and the complete patch is at https://github.com/r-dbi/DBI/tree/ca42bd8ff5d03616d78499f22eccd6799bc1a8b8/experiments/2026-11-29-s7-vendored. Generated by Claude Code |
Issue draft 6 of 6 for the S7 repository (not posted there)Source: Feature request: S7 generics that are also S4 generics, to move a generic from S4 to S7 without breaking installed packagesA package that owns widely used S4 generics, such as DBI, cannot move them to S7 one release at a time: once a generic is an S7 generic, packages installed against the S4 generic break until they are changed and reinstalled. A way to create an S7 generic that also is an S4 generic, with S4 methods dispatched first and S7 methods after, would allow the move without upgrading all dependent packages at the same time. ReprexWith S7 1.0.0 from CRAN: library(S7)
packageVersion("S7")
#> [1] '1.0.0'
area <- new_generic("area", "shape")
Circle <- new_class("Circle", properties = list(r = class_numeric))
method(area, Circle) <- function(shape) pi * shape@r^2
## An S7 generic is not an S4 generic, so an installed package whose NAMESPACE has
## exportMethods(area) or importMethodsFrom(<pkg>, area) no longer loads
## once the generic moves from S4 to S7:
methods::is(area, "genericFunction")
#> [1] FALSE
## Expected: a way to get TRUE here
## setMethod(), as in packages written for the S4 generic,
## creates a new S4 generic that masks the S7 generic:
methods::setClass("Square4", slots = c(side = "numeric"))
methods::setMethod("area", "Square4", function(shape) shape@side^2)
#> Creating a generic function from function 'area' in the global environment
class(area)
#> [1] "standardGeneric"
#> attr(,"package")
#> [1] "methods"
## Expected: one generic with both methods
area(methods::new("Square4", side = 2))
#> [1] 4
area(Circle(r = 1))
#> Error in `S7_dispatch()`:
#> ! Must be called from within an S7 generic.In packages, it is worse: an installed package whose Expected and actualExpected: a supported way to keep one generic that S4 code can register methods for, with ProposalAn
With the S7 adapted in the experiment record: ## Needs the S7 adapted in this record, which adds S4_generic()
library(S7)
packageVersion("S7")
#> [1] '1.0.0.9000'
area7 <- new_generic("area", "shape", function(shape) {
message("generic body runs once")
S7_dispatch()
})
S4_generic(area7)
methods::is(area, "genericFunction")
#> [1] TRUE
## S4 methods, as installed packages register them:
methods::setClass("Square4", slots = c(side = "numeric"))
methods::setMethod("area", "Square4", function(shape) shape@side^2)
area(methods::new("Square4", side = 2))
#> generic body runs once
#> [1] 4
## S7 methods, registered with method<- on the S4 generic, live in the S7 generic:
Circle <- new_class("Circle", properties = list(r = class_numeric))
method(area, Circle) <- function(shape) pi * shape@r^2
area(Circle(r = 1))
#> generic body runs once
#> [1] 3.141593
method(area, Circle)
#> <S7_method> method(area, Circle)
#> function (shape)
#> pi * shape@r^2
## An S4 class without an S4 method falls through to S7 dispatch,
## which finds the method for an S7 parent:
Shape <- new_class("Shape", abstract = TRUE)
S4_register(Shape)
method(area, Shape) <- function(shape) NA_real_
methods::setClass("Blob4", contains = "Shape")
area(methods::new("Blob4"))
#> generic body runs once
#> [1] NAIn the record, DBI's Limits: by design, methods registered with Found while investigating a move of DBI's classes and generics from S4 to S7, in #795. The experiment record with the adapted S7 and the complete patch is at https://github.com/r-dbi/DBI/tree/ca42bd8ff5d03616d78499f22eccd6799bc1a8b8/experiments/2026-11-29-s7-vendored. Generated by Claude Code |
Question: How to proceed with S7, now that an adapted S7 makes the move viable?The vendored S7 record (R 4.5.3, S7 1.0.0 with patches) finds that DBI can make its base classes S7 classes and move generics to S7 one at a time, exporting each as an S4 generic with a new
Kirill decides. If nobody decides, nothing moves to S7 and the record stays on this PR. Generated by Claude Code |
Question: File the six issue drafts in the S7 repository?The drafts are posted here for reading, one per comment: 01
Kirill decides; nothing is posted without his go-ahead. If nobody decides, nothing is filed. Generated by Claude Code |
Accepted limitationsEarlier record (
Vendored S7 record (
Generated by Claude Code |
Investigates whether DBI's virtual base classes (
DBIObject,DBIDriver,DBIConnection,DBIResult,DBIResultArrow) and generics could move from S4 to S7, what that would mean for the existing S4 backends, and whether it would simplify the per-object.dbistate of #794. As Kirill asked, a second experiment adapts a vendored copy of S7 to fix the limitations the first one found, so that the move works without upgrading all backends at once.Result
Two experiment records, each with scripts and output (R 4.5.3, S7 1.0.0);
experiments/README.mdlists them, and.Rbuildignoreexcludes the folder from the package build.experiments/2026-11-29-s7/, with stock S7:attr(x, ".dbi")stays necessary.S4_register(), and S7's own tools then fail on backend objects.experiments/2026-11-29-s7-vendored/, with an adapted copy of S7 (MIT, withS7.diffagainst the CRAN tarball):prop(), dispatch andS7_inherits()for S4 subclasses of abstract S7 classes andS4_register()of a concrete child, cache S4 dispatch, and addS4_generic(), which makes an S7 generic also an S4 generic. S7's own 615 tests pass unchanged; one documented behavior change for pure S7 users.dbConnect(),dbDisconnect()anddbGetQuery(), the RSQLite 3.54.1 and duckdb 2.0.1 binaries built against DBI 1.3.0 work unchanged; RSQLite's tests with DBItest (881) and DBI's (711) pass, as onmain. A minimal S4 and a minimal S7 backend work side by side.getMethod()andexistsMethod()no longer find methods that moved to S7.dbGetQuery()on RSQLite was 5 to 14 % slower in one recorded run.R CMD checkof the S7 DBI, duckdb's own tests, odbc, RPostgres, RMariaDB, bigrquery, adbi, other platforms.Status
https://claude.ai/code/session_01Hr1rd6RgjpQxckjWTEReje