Skip to content

Keep district and district_std columns in output files - #35

Merged
shauntruelove merged 10 commits into
mainfrom
copilot/fix-drop-district-column
Jul 16, 2026
Merged

shauntruelove merged 10 commits into
mainfrom
copilot/fix-drop-district-column

Conversation

Copilot AI commented Jul 14, 2026 •

Copy link
Copy Markdown

The district column (added to improve matching accuracy) was being silently dropped from all output files because format_select_columns filtered to an explicit allowlist that didn't include it.

Changes

  • R/final_format_utils.R: Add "district" and "district_std" to optional_cols in the format_select_columns call inside generate_model_input_tables. Both columns are preserved when present, silently omitted when absent.
optional_cols = c("school_type", "school_level", "excluded_note",
                  "addr_clean", "city", "zip", "state", "business_status",
                  "lat", "lon", "district", "district_std")  # added
  • tests/testthat/test-final_format_utils.R: New test file covering format_select_columns — verifies district columns are retained when present and that the function still handles their absence gracefully.

Copilot AI linked an issue Jul 14, 2026 that may be closed by this pull request
Copilot AI changed the title [WIP] Fix issue with dropping district column from output files Keep district and district_std columns in output files Jul 14, 2026
Copilot AI requested a review from shauntruelove July 14, 2026 20:13
…x R CMD check

R CMD check runs all .R files in tests/, but test_modular_functions.R uses
source() with relative paths (e.g. source('R/clean_state_data.R')) which fail
because the working directory during R CMD check is not the package root.

Moving to inst/scripts/ preserves the file for manual use while preventing
R CMD check from executing it automatically.
Copilot AI requested a review from shauntruelove July 15, 2026 15:23
@shauntruelove
shauntruelove marked this pull request as ready for review July 15, 2026 16:24
Copilot AI review requested due to automatic review settings July 15, 2026 16:24

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR aims to ensure district and district_std columns are preserved in the final formatted output (when present) rather than being dropped by column selection logic. It also includes additional robustness changes in school-name matching and a new standalone script for testing modular preprocessing/DQA functions.

Changes:

  • Preserve district and district_std during final formatting output column selection.
  • Add test coverage for format_select_columns() to validate retention/absence behavior for district columns.
  • Harden matching utilities and adjust matching tests; add an inst/scripts/ modular-function test runner script.

Reviewed changes

Copilot reviewed 4 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
tests/testthat/test-match_schools_names.R Tweaks input strings in matching tests (non-exact/unmatched scenarios).
tests/testthat/test-final_format_utils.R Adds unit tests ensuring district columns are kept when present and omitted when absent.
R/matching_schools_utils.R Improves edge-case handling in matching (drop behavior, empty/NULL-safe handling).
R/final_format_utils.R Keeps district and district_std as optional columns in final formatting output.
inst/scripts/test_modular_functions.R Adds a standalone script to exercise modular preprocessing/DQA functions on synthetic data.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread R/final_format_utils.R
Comment on lines 1234 to 1241
kinder_dat <- format_select_columns(
kinder_dat,
required_cols = c("school_id", "year", "school_name", "county_name",
"enrollment", "current", "med_exempt", "rel_exempt"),
optional_cols = c("school_type", "school_level", "excluded_note",
"addr_clean", "city", "zip", "state", "business_status",
"lat", "lon")
"lat", "lon", "district", "district_std")
)
Comment thread R/final_format_utils.R
Comment on lines 1234 to 1241
kinder_dat <- format_select_columns(
kinder_dat,
required_cols = c("school_id", "year", "school_name", "county_name",
"enrollment", "current", "med_exempt", "rel_exempt"),
optional_cols = c("school_type", "school_level", "excluded_note",
"addr_clean", "city", "zip", "state", "business_status",
"lat", "lon")
"lat", "lon", "district", "district_std")
)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added district and district_std as "character" entries in expected_classes in commit Add district and district_std to expected_classes in format_fix_column_classes(). These columns will now be coerced to character type consistently with other optional text columns.

@shauntruelove
shauntruelove merged commit 498ba0b into main Jul 16, 2026
1 check passed
@shauntruelove
shauntruelove deleted the copilot/fix-drop-district-column branch July 16, 2026 14:19
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.

Keep "district" column

3 participants