Skip to content

Refuse the category names n, ptarget and nn in race models - #594

Merged
GidonFrischkorn merged 1 commit into
dev-1.6.0from
race-stan-reserved
Oct 18, 2026
Merged

GidonFrischkorn merged 1 commit into
dev-1.6.0from
race-stan-reserved

Conversation

@GidonFrischkorn

Copy link
Copy Markdown
Collaborator

Refuse the category names n, ptarget and nn in race models

A follow-up to #499. A race model's custom version turns each response category into a parameter of the generated likelihood, so a category cannot take a name the Stan program already declares. #499 refuses Stan keywords and brms's threading names seq, start and end. Three more names collide:

  • n: brms adds group-level effects to a parameter in a for (n in 1:N) loop, so a category n fails in stanc as soon as any parameter has a random effect, with or without threading.
  • ptarget and nn: brms declares them in threaded programs.

Before this PR such a category passed the name check and failed in stanc with "Identifier ... is already in use". Now race_category_names() refuses it with the same message as the other reserved words. Each race model can drop its own copy of these names.

Found while cleaning up the race-model PRs (#500, #501, #502): with the name guard switched off, a category n failed stanc for both LBA and RDM, threaded or not, and ptarget and nn failed under threading.

Changes

  • R/utils.R: n, ptarget and nn added to .stan_reserved, with the reason for each.
  • tests/testthat/test-helpers-race.R: three expectations, one per name. They fail without the change.

No user-visible change outside the race models, which are not released yet. So there is no NEWS entry.

Checks (local, macOS)

  • Full test suite (NOT_CRAN=true, Stan tests on, 4 workers): 1917 tests, 0 failed, 0 skipped.

Merge order

Merge this before #500, #501 and #502, with a merge commit rather than a squash: each of those branches already contains this commit.

brms adds group-level effects in a `for (n in 1:N)` loop and, under
threading, declares `ptarget` and `nn` as well, so a race-model category
with one of these names passed the name check and then failed in stanc.
The three names now join seq, start and end in the shared list, and the
race models no longer need to list them themselves.
@GidonFrischkorn
GidonFrischkorn merged commit 3a4ca8f into dev-1.6.0 Oct 18, 2026
7 checks passed
@GidonFrischkorn
GidonFrischkorn deleted the race-stan-reserved branch October 18, 2026 17:02
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