Skip to content

Refactor scalar case_when() branches in convert_output() to if/else - #345

Merged
Schiano-NOAA merged 6 commits into
mainfrom
copilot/refactor-case-when-to-if-else
Aug 19, 2026
Merged

Refactor scalar case_when() branches in convert_output() to if/else#345
Schiano-NOAA merged 6 commits into
mainfrom
copilot/refactor-case-when-to-if-else

Conversation

Copilot AI commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

convert_output() contained scalar-condition dplyr::case_when() branches that trigger dplyr 1.2.x deprecation warnings (size 1 LHS with vector RHS). This PR replaces those branches with explicit if/else logic in the affected paths while preserving existing output behavior.

  • Scope

    • Updated scalar conditional branches inside R/convert_output.R where case_when() was being used as control flow rather than vectorized row-wise logic.
  • Code changes

    • Replaced scalar case_when() used to derive sex from sexes column presence with direct if/else.
    • Replaced scalar case_when() used to map fleet values after out_new <- Reduce(rbind, out_list) with direct if/else.
  • Regression guard

    • Added a focused test in tests/testthat/test-convert_output.R asserting convert_output() does not emit warnings for a representative SS3 fixture.
# Before
fleet = dplyr::case_when(
  any(unique(out_new$fleet) %in% fleet_names) ~ fleet,
  TRUE ~ fleet_names[fleet]
)

# After
fleet = if (any(unique(out_new$fleet) %in% fleet_names)) fleet else fleet_names[fleet]

Co-authored-by: Schiano-NOAA <125507018+Schiano-NOAA@users.noreply.github.com>
Copilot AI changed the title [WIP] Refactor all dplyr::case_when() to dplyr::if_else() in convert_output() Refactor scalar case_when() branches in convert_output() to if/else Aug 12, 2026
Copilot AI requested a review from Schiano-NOAA August 12, 2026 14:19
@Schiano-NOAA
Schiano-NOAA marked this pull request as ready for review August 12, 2026 15:00
@Schiano-NOAA

Copy link
Copy Markdown
Collaborator

@copilot please also look through all other functions in the R/ folder and replace case_when with the if else scalar

Co-authored-by: Schiano-NOAA <125507018+Schiano-NOAA@users.noreply.github.com>

Copilot AI commented Aug 12, 2026

Copy link
Copy Markdown
Contributor Author

@copilot please also look through all other functions in the R/ folder and replace case_when with the if else scalar

Addressed in commit 3726423. I reviewed scalar-condition case_when() usage across the R functions and replaced the remaining scalar-control-flow instance in plot_aa() (R/utils_plot.R) with if/else, and added a focused no-warning assertion in tests/testthat/test-utils_plot.R.

Co-authored-by: Schiano-NOAA <125507018+Schiano-NOAA@users.noreply.github.com>
Co-authored-by: Schiano-NOAA <125507018+Schiano-NOAA@users.noreply.github.com>
Copilot AI requested a review from Schiano-NOAA August 18, 2026 19:01
@Schiano-NOAA
Schiano-NOAA merged commit ccabb95 into main Aug 19, 2026
8 checks passed
@Schiano-NOAA
Schiano-NOAA deleted the copilot/refactor-case-when-to-if-else branch August 19, 2026 18:53
github-actions Bot added a commit that referenced this pull request Aug 19, 2026
…ccabb95 Refactor scalar `case_when()` branches in `convert_output()` to `if`/`else` (#345)) [skip ci]
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.

[refactor]: change all dplyr::case_when() to dplyr::if_else() in convert_output()

2 participants