Skip to content

Add check.rwl() and enforce rwl class uniformly across public functions#37

Open
AndyBunn wants to merge 4 commits into
masterfrom
check-rwl-enforcement
Open

Add check.rwl() and enforce rwl class uniformly across public functions#37
AndyBunn wants to merge 4 commits into
masterfrom
check-rwl-enforcement

Conversation

@AndyBunn
Copy link
Copy Markdown
Collaborator

Summary

  • Adds check.rwl(), a new exported validation/coercion function that provides a single, consistent entry point for rwl validation across the package. If the input is not class rwl, coercion is attempted via as.rwl(); on success a warning is issued; on failure a single informative error names both the class problem and the structural reason coercion failed. After class validation, check.rwl() also warns about internal NAs and names the affected series, directing the user to fill.internal.NA().
  • Adds a numeric-column check to as.rwl() that was previously missing.
  • Replaces ad-hoc is.data.frame() / warning-only class checks in 19 public functions (bai.in, bai.out, ccf.series.rwl, cms, common.interval, corr.rwl.seg, corr.series.seg, detrend, i.detrend, interseries.cor, pointer, rcs, rwl.stats, seg.plot, series.rwl.plot, spag.plot, ssf, strip.rwl, xdate.floater) with a single check.rwl() call.
  • Renames first argument x → rwl in sgc() and x → rwi in chron() and chron.ars() to correctly reflect what each function expects; updates man pages accordingly.
  • Adds 17 new testthat tests covering check.rwl() and as.rwl().

Test plan

  • devtools::test('.') passes with FAIL 0 (currently FAIL 0 | WARN 37 | SKIP 0 | PASS 454)
  • check.rwl() on a proper rwl is silent and returns input unchanged
  • check.rwl() on a plain data.frame warns "Coerced successfully" and returns an rwl
  • check.rwl() on structurally bad input (non-consecutive years, non-numeric columns, non-data.frame) stops with a single message describing both the class problem and the structural cause
  • check.rwl() on an rwl with internal NAs warns and names the affected series
  • chron(rwi, ...) and chron.ars(rwi, ...) work normally — no spurious "not class rwl" warnings from the detrend → chron workflow

AndyBunn and others added 4 commits May 21, 2026 18:04
Previously, check.rwl() warned before attempting coercion, so a
structural failure (e.g. non-consecutive years) produced a confusing
pair of messages in reverse causal order, with an internal function
name (as.rwl) in the error.

Now coercion is attempted first inside tryCatch. On failure, a single
stop() names the class problem and the structural reason together.
The warning only fires on success, confirming coercion worked.

Before:
  Error in as.rwl(rwl): 'x' must have consecutive integers as row names (years)
  In addition: Warning message: 'rwl' is not class "rwl". Attempting to coerce.

After:
  Error: 'rwl' is not class "rwl" and coercion failed: 'x' must have
         consecutive integers as row names (years)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…ages

sgc() takes ring-width data (rwl), not a generic object — rename the
argument from x to rwl for consistency with the rest of the package,
and let check.rwl() validate it.

chron() and chron.ars() take detrended ring-width indices (rwi), not
raw ring widths. Rename x→rwi to make the expected input explicit.
Remove the check.rwl() calls added in the previous commit: rwi is not
an rwl and enforcing that class would fire a spurious coercion warning
on every normal detrend() → chron() workflow.

Update \usage, \arguments, and \value in the corresponding man pages.
The \seealso pointer in chron.Rd and chron.ars.Rd is corrected from
read.rwl to detrend, since detrend is what actually produces rwi.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Covers happy path, coercion, structural failures, internal NA
detection, and all as.rwl() error conditions (17 tests total).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Documents check.rwl(), as.rwl() numeric column check, uniform rwl
validation across 19 public functions, argument renames in sgc/chron/
chron.ars, and the new test suite additions.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant