Skip to content

util: argument predicates for named stopifnot() checks - #82

Merged
mmyrte merged 1 commit into
claude/confident-albattani-56osfg-crosstabfrom
claude/argument-assertions
Oct 19, 2026
Merged

mmyrte merged 1 commit into
claude/confident-albattani-56osfg-crosstabfrom
claude/argument-assertions

Conversation

@mmyrte

@mmyrte mmyrte commented Oct 19, 2026

Copy link
Copy Markdown
Member

Stacked on #57, as asked in its review. Merge #57 first; this PR's base then moves to develop.

The argument checks spelled out length(x) == 1L && as.integer(x) == x and similar combinations in every function. R/util.R now has predicates for the conditions of a named stopifnot(), so the name stays the message the user sees:

stopifnot("id_period must be a single integer" = is_scalar_integerish(id_period))
  • is_integerish(): finite whole numbers, any length including 0;
  • is_scalar_integerish();
  • is_scalar_numeric();
  • is_scalar_character();
  • is_scalar_logical(): TRUE or FALSE.

None of them accepts NA.

They replace the hand-written checks throughout R/: allocators, views, neighbors_t, pred_data_t, runs_t, trans_models_t, lp_problem, ducklake_db, coords_t and validation. devdocs/style/r.md points to them.

The only check left spelled out is distance_breaks in neighbors_t, which needs at least two elements. The trans_rates_lp penalty checks stay as they are because terminal_band may be NA.

Stricter checks

  • id_periods in alloc_clumpy(), alloc_dinamica() and alloc_greedy() must be whole numbers, not just numeric.
  • select_maximize may not be NA. In alloc_dinamica()'s eval_alloc_params_t() path, the old select_maximize || !select_maximize also accepted non-logical values.
  • $next_id(n = ) rejects a fractional n instead of truncating it.
  • create_coords_t_square() accepts an integer resolution as well as a double, and now reports through stopifnot() instead of stop().

Tests

test_util.R checks each predicate against 11 candidate values: 1L, 1, 1.5, c(1, 2), integer(0), NA_integer_, Inf, "1", "a", TRUE and NA. tinytest::build_install_test(): all ok, 656 results.


Generated by Claude Code

The length / as.integer / is.character combinations repeated across the
package made the argument checks hard to read. is_integerish(),
is_scalar_integerish(), is_scalar_numeric(), is_scalar_character() and
is_scalar_logical() replace them everywhere; none accepts NA, so a few checks
become stricter: id_periods must be whole numbers, select_maximize may not be
NA, next_id() rejects a fractional n instead of truncating it, and
create_coords_t_square() takes an integer resolution too.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019fog72qNWbuSjiGBWuP3np
@mmyrte
mmyrte added this pull request to stack #83 October 19, 2026 12:33
@mmyrte
mmyrte merged commit 08aa38e into develop Oct 19, 2026
2 checks passed
@mmyrte
mmyrte deleted the claude/argument-assertions branch October 20, 2026 15:05
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.

2 participants