Don't rely on S4 initialize dispatch to build tinytable objects - #688
Merged
Merged
Conversation
`tt()` created its object with `new("tinytable", ..., colnames = colnames)`,
where `colnames` is an argument of the custom `initialize` method rather than
a slot. Methods defined for generics owned by the `methods` package are merged
into the live dispatch table by `cacheMetaData()` at load time, and that merge
is skipped when `methods` is not attached as the namespace loads. In such a
session `new()` falls back to the default `initialize()`, which treats every
argument as a slot name and quits with "invalid name for slot of class
tinytable: colnames".
Move the slot-filling logic into an ordinary function, `tinytable_init()`, and
call it directly from `tt()`. The `initialize` method is kept as a thin
delegate so `new("tinytable", ...)` keeps working where dispatch is available.
Fixes #687
Claude-Session: https://claude.ai/code/session_01KXi6DkijKg5gMLajPJiWbP
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #687.
Problem
tt()built its object withmethods::new("tinytable", ..., colnames = colnames).colnamesis not a slot — it is an argument of the custominitializemethod.Methods defined for generics owned by the methods package are merged into the live dispatch table by
cacheMetaData()at load time, and that merge is skipped whenmethodsis not attached as the namespace loads. In such a sessionnew()falls back to the defaultinitialize(), which treats every named argument as a slot and errors:The installed metadata is fine — the namespace does contain
.__T__initialize:methods. Only the merge into the live table is missing:Attaching
methodsafterwards does not repair it; the merge only happens at load. The package's own generics (build_eval,style_eval, …) are unaffected — their tables live in the namespace.Reproducer, both examples from the issue:
This was latent before
colnameswas added: every argument used to be a real slot, so the fallback ran without error but silently skipped the dynamic setup (@id,@nrow,@ncol,@nhead,@names).Fix
Move the slot-filling logic out of the
initializemethod into an ordinary function,tinytable_init(), and call it directly fromtt(). Theinitializemethod stays as a thin delegate, sonew("tinytable", ...)keeps working where dispatch is available.Testing
methodsunattached.inst/tinytest/test-bugfix.Rrunstt()+style_tt()+save_tt()in a subprocess started withoutmethodsin the default packages. It is skipped unlesstinytableresolves to an installed package, sopkgload::load_all()workflows are unaffected. Verified that the oldnew("tinytable", colnames = TRUE)path still fails in that subprocess, so the test genuinely guards the regression.tinytest::run_test_dir(): all ok, 642 results.R CMD check: Status OK, 643 results (the new test runs there).Note on the CRAN report
I could not determine what dropped
methodson win-builder. R's own vignette-rebuild step does not setR_DEFAULT_PACKAGES(only static-analysis subprocesses do, viaR_runR2), and I reproduced the reporter's full chain locally — R CMD check →quarto::htmlengine → quarto CLI → R — wheremethodsis attached and the render succeeds. Whatever causes it appears specific to that machine's environment. This fix removes the failure mode regardless of the cause.https://claude.ai/code/session_01KXi6DkijKg5gMLajPJiWbP