Skip to content

fix(nitrogen): port sjos_levels in the afsetools order it documents - #772

Open
lbm364dl wants to merge 1 commit into
mainfrom
claude/sjos-levels-order-754
Open

fix(nitrogen): port sjos_levels in the afsetools order it documents#772
lbm364dl wants to merge 1 commit into
mainfrom
claude/sjos-levels-order-754

Conversation

@lbm364dl

Copy link
Copy Markdown
Collaborator

What was wrong (mechanism)

whep::sjos_levels documents its level labels and colours as ported by value
from afsetools::load_vectors(), but afsetools wraps SJOS_levels in rev():

# afsetools/R/load_vectors.R:684
assign("SJOS_levels", rev(c("Within_boundary Under", ..., "Exceedance Over")), envir = env)

so its realised element 1 is "Exceedance Over". whep assigned order = 1L to
"Within_boundary Under" — the ordering was inverted relative to the vector it
says it ported. Verified by reading both files; the six colours match
SJOS_colours exactly, only the order differed.

No classification value changes: classify_sjos_n() uses sjos_levels$level
only as the factor levels of sjos_class, so membership is unaffected. What
changes is levels(sjos_class), i.e. the stacking and legend order of any
figure built from these levels — and Global stacks on the reversed vector
(Global/R/SJOS_N_figs.R:188, Global/R/SJOS_N.R:241), so the reversed order
is the one that reproduces its figures.

Classification: mechanical (faithfulness to a named source), with one visible
presentation consequence stated above. The issue offered the alternative of
keeping whep's ascending order and rewording the @source instead; I took the
faithful-port option because nourish_levels is already literal about its own
source vector (Nour_levels, unreversed at load_vectors.R:683), so the two
tables now port from afsetools the same way, and because it is the order
Global's figures use. Happy to flip to the doc-only option if you prefer the
ascending reading — say so and I will.

What changed

  • data-raw/sjos_n_coefficients.R: sjos_levels rows reversed
    ("Exceedance Over" = 1L … "Within_boundary Under" = 6L), with a comment
    naming load_vectors.R:684 and the rev().
  • data/sjos_levels.rda rebuilt by re-running the builder (the other three
    tables it writes came out byte-identical).
  • R/datasets_sjos_n.R: @description/@format/@source now state the
    ordering explicitly, so it is a stated ported choice rather than an accident.
  • tests/testthat/test_datasets_sjos_n.R: the order assertion now compares
    against rev(<ascending vector>) — written the way afsetools writes it — and
    additionally asserts order == seq_along(level).

Verification

man/ regenerated with devtools::document(), air format . run, both
changed R files and the data-raw script lint clean.

Test failing before the fix (old data/sjos_levels.rda restored via
git stash, new test in place):

Failure ('test_datasets_sjos_n.R:47:3'): sjos/nourish level tables are ordered and coloured
s$level (`actual`) not equal to `afsetools_sjos_levels` (`expected`).

    actual                     | expected
[1] "Within_boundary Under"    - "Exceedance Over"          [1]
[2] "Within_boundary Adequate" - "Exceedance Adequate"      [2]
[3] "Within_boundary Over"     - "Exceedance Under"         [3]
[4] "Exceedance Under"         - "Within_boundary Over"     [4]
[5] "Exceedance Adequate"      - "Within_boundary Adequate" [5]
[6] "Exceedance Over"          - "Within_boundary Under"    [6]

[ FAIL 1 | WARN 0 | SKIP 0 | PASS 27 ]

Passing after, together with the consumers and the data-raw freshness gate:

devtools::test(filter = "datasets_sjos_n|sjos_n_class|data_raw_freshness")
[ FAIL 0 | WARN 0 | SKIP 0 | PASS 105 ]

Not carried (out of scope, still open in the issue text): afsetools
Nourish_colours_tot / Nourish_levels_tot, the "Total" variants.

Closes #754.

🤖 Generated with Claude Code

whep::sjos_levels documents its labels, order and colours as ported by
value from afsetools::load_vectors(), but afsetools wraps SJOS_levels in
rev() (load_vectors.R:684), so its realised element 1 is "Exceedance
Over" while whep assigned order = 1L to "Within_boundary Under". The
colours were ported correctly; only the ordering was inverted.

classify_sjos_n() uses sjos_levels$level as the factor levels of its
sjos_class column, so the inversion did not change any classification
value — only the level order, i.e. the stacking and legend order of any
figure meant to reproduce Global's, which stacks on the reversed vector
(Global/R/SJOS_N_figs.R:188). nourish_levels was already literal about
its own source vector (Nour_levels, unreversed), so this makes the two
tables consistent in how they port from afsetools.

Reverses the sjos_levels rows (and rebuilds data/sjos_levels.rda), and
states the ordering explicitly in the roxygen so it reads as the ported
choice it is rather than an accident.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@lbm364dl lbm364dl self-assigned this Aug 12, 2026
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.

sjos_levels ordering is inverted relative to the afsetools vector it documents as ported by value

1 participant