chore: dead code and unused function audit and removal#41
Conversation
…klist Agent-Logs-Url: https://github.com/pbulsink/HockeyModel/sessions/86e9affa-6ae3-4270-8e6f-2f4dc3826170 Co-authored-by: pbulsink <5419974+pbulsink@users.noreply.github.com>
Dead Code & Unused Function AuditThis document lists functions that are never called (or only called from tests),
|
| Category | Count |
|---|---|
| Functions never called in production | 10 |
| Functions called only from tests | 4 |
| Dead/wasted computation blocks | 2 |
| Unimplemented stub API routes | 3 |
Commented-out rtoot call sites |
16 |
| Commented-out old seeding logic (lines) | ~186 |
|
@copilot could I completely remove the R/dc_iterative.R file without messing up any of the function calls from R/main.R? If I remove the R/api-output.R file as I don't use plumber interaction, what else can I remove (i.e. in DESCRIPTION) to clean up the package code? |
Removing Yes, you can safely remove the entire file. No production code in any other R file calls its functions — I searched all of To do a clean removal you'd also want to:
Removing You can delete that file with no ripple effects — nothing in the package sources or imports it, and |
|
Some items were not removed as they're called periodically in dev |
There was a problem hiding this comment.
Pull request overview
This PR removes unused/dead code across the HockeyModel package, including dropping the (apparently unused) iterative Dixon–Coles implementation and cleaning out related exports, docs, tests, and legacy/commented-out sections. It also introduces new behavior around skipping playoff simulation when prediction files are “stale”.
Changes:
- Removed iterative-model implementation (
R/dc_iterative.R), its exported functions, datasets, documentation, and tests/VCR cassette. - Removed additional unused/internal helpers (e.g.,
mutate_cond,validateWins,updateScoresAPI_byGameID,DCweights_old) plus their docs/tests. - Cleaned up legacy/commented-out posting logic and added early-return handling when
simulatePlayoffs()yieldsNULL.
Reviewed changes
Copilot reviewed 39 out of 41 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| DESCRIPTION | Removes tictoc from Suggests. |
| NAMESPACE | Removes exports for iterative-model and other deleted helpers. |
| R/api-interface.R | Deletes unused internal helpers (updateScoresAPI_byGameID(), validateWins()). |
| R/api-output.R | Removes unused/unimplemented plumber route stubs. |
| R/data.R | Removes documentation entries for iterative datasets. |
| R/dc_iterative.R | Deletes the iterative Dixon–Coles implementation entirely. |
| R/dixon-coles.R | Removes deprecated internal weighting helper DCweights_old(). |
| R/league.R | Adds staleness gating/early return when loading predictions implicitly in simulatePlayoffs(). |
| R/main.R | Removes commented-out rtoot calls; adds NULL guard for tweetPlayoffOdds() when simulatePlayoffs() returns NULL. |
| R/utils.R | Removes mutate_cond() and gameId validator helpers (gId(), is_valid_gameId). |
| tests/testthat/_vcr/iterative.yml | Removes VCR cassette for iterative tests. |
| tests/testthat/test-dc_iterative.R | Removes iterative-model test coverage. |
| tests/testthat/test-utils.R | Removes tests for mutate_cond() (function also removed). |
| man/DCweights_old.Rd | Removes documentation for deleted internal helper. |
| man/gId.Rd | Removes documentation for deleted internal helper. |
| man/getIterativePredictions.Rd | Removes documentation for deleted iterative helper. |
| man/getIterativeTable.Rd | Removes documentation for deleted exported function. |
| man/getNewIterativeRankings.Rd | Removes documentation for deleted internal helper. |
| man/getReplacementIterativeParameters.Rd | Removes documentation for deleted exported function. |
| man/getReplacementRankings.Rd | Removes documentation for deleted exported function. |
| man/getTeamRankings.Rd | Removes documentation for deleted iterative helper. |
| man/iterateGame.Rd | Removes documentation for deleted iterative helper. |
| man/iterateSeason.Rd | Removes documentation for deleted iterative helper. |
| man/iterativeDailyUpdate.Rd | Removes documentation for deleted iterative helper. |
| man/iterativeGamePredict.Rd | Removes documentation for deleted exported function. |
| man/iterativeOddsTable.Rd | Removes documentation for deleted iterative helper. |
| man/iterativeParameters.Rd | Removes documentation for removed dataset. |
| man/iterativeRankings.Rd | Removes documentation for removed dataset. |
| man/iterative_season_progress.Rd | Removes documentation for deleted iterative helper. |
| man/mutate_cond.Rd | Removes documentation for deleted exported function. |
| man/optimizeIterative.Rd | Removes documentation for deleted exported function. |
| man/optimizeIterative_WL_Internal.Rd | Removes documentation for deleted internal helper. |
| man/optimizeIterative_XG_Internal.Rd | Removes documentation for deleted internal helper. |
| man/readIterativePredictions.Rd | Removes documentation for deleted internal helper. |
| man/saveIterativePredictions.Rd | Removes documentation for deleted internal helper. |
| man/updateIterativeRankings.Rd | Removes documentation for deleted internal helper. |
| man/updateRankingsToToday.Rd | Removes documentation for deleted internal helper. |
| man/updateScoresAPI_byGameID.Rd | Removes documentation for deleted internal helper. |
| man/validateWins.Rd | Removes documentation for deleted internal helper. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| pdates <- substr(filelist, 1, 10) # gets the dates list of prediction | ||
| pdates <- pdates[pdates != "graphics"] | ||
| lastp <- as.Date(max(pdates)) | ||
| if(as.Date(lastp) < Sys.Date()-7){ | ||
| return(NULL) |
There was a problem hiding this comment.
@copilot apply changes based on this feedback. Note that there's other areas where lastp is determined like this so please confirm all are in sync
There was a problem hiding this comment.
Done in commits 25034b1 and a2216e5.
Added get_prediction_dates(dir) in R/utils.R — it filters list.files() to files matching ^YYYY-MM-DD-predictions\.RDS$ via regex, strips out any NA dates, validates the directory exists, and returns a sorted Date vector.
All five call sites are now in sync:
compile_predictions()(league.R) — uses helper, aborts with informative error if emptysimulatePlayoffs()(league.R) — uses helper, emitscli_alert_info()(not silentNULL) for both empty and stale casesupdatePredictions()(main.R) — uses helper, falls back to season-start date if no files yettweetPace()(main.R) — uses helper, aborts if emptyplot_pace_by_team()(graphics.R) — uses helper, aborts if empty
| export(getAPISeries) | ||
| export(getCurrentPWHLSeason) | ||
| export(getCurrentSeason8) | ||
| export(getIterativeTable) | ||
| export(getM) | ||
| export(getNHLSchedule) | ||
| export(getNHLScores) | ||
| export(getPWHLPlayoffSeries) | ||
| export(getPWHLSchedule) | ||
| export(getPWHLScores) | ||
| export(getPWHLSeasons) |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
…files Adds get_prediction_dates() in R/utils.R that filters list.files() output to only YYYY-MM-DD-predictions.RDS entries via regex, returning a sorted Date vector. Replaces the fragile pdates[pdates != "graphics"] pattern at all five call sites (compile_predictions, simulatePlayoffs, updatePredictions, tweetPace, plot_pace_by_team). simulatePlayoffs() now emits cli_alert_info() instead of silently returning NULL when predictions are missing or stale. Agent-Logs-Url: https://github.com/pbulsink/HockeyModel/sessions/c9b20b30-ae42-41d3-a25e-3c11ece18973 Co-authored-by: pbulsink <5419974+pbulsink@users.noreply.github.com>
- Validate dir exists before calling list.files(); abort with informative
message if NULL or non-existent
- Filter out NA dates produced by any malformed filenames that pass regex
- Fix cli_alert_info() message to use {.val {lastp}} so the date is
properly interpolated in the CLI output
Agent-Logs-Url: https://github.com/pbulsink/HockeyModel/sessions/c9b20b30-ae42-41d3-a25e-3c11ece18973
Co-authored-by: pbulsink <5419974+pbulsink@users.noreply.github.com>
Removes unused/dead code across the HockeyModel package based on a thorough audit.
Changes Made
Removed functions and files
R/dc_iterative.R— entire iterative Dixon–Coles implementation removed (no production callers); associated exports, datasets (iterativeParameters,iterativeRankings), documentation, tests, and VCR cassette also removed.tictocdropped fromSuggestsin DESCRIPTION.R/utils.R: removedgId(),is_valid_gameId(), andmutate_cond()(superseded or unused in production)R/dixon-coles.R: removedDCweights_old()(fully replaced byDCweights())R/api-interface.R: removedupdateScoresAPI_byGameID()andvalidateWins()(never called)R/api-output.R: removed stub plumber routes (/cup-odds,/pace-graphic,/points-distribution) that always returnedNULLDead code cleaned up
rtoot::post_toot()call sites throughoutR/main.R(replaced byatrrr::post()but left as comments)R/league.R(lines 1724–1910)optimizeIterative_WL_Internal()andoptimizeIterative_XG_Internal()inR/dc_iterative.RBug fix: robust prediction file discovery
get_prediction_dates(dir)internal helper inR/utils.Rthat filterslist.files()output to onlyYYYY-MM-DD-predictions.RDSfiles via regex, validates the directory exists, and strips anyNAdates from malformed filenamespdates[pdates != "graphics"]pattern at all five call sites:compile_predictions(),simulatePlayoffs(),updatePredictions(),tweetPace(),plot_pace_by_team()simulatePlayoffs()now emits an informativecli_alert_info()message (instead of silently returningNULL) when prediction files are missing or staleOther
simulatePlayoffs()returnsinvisible(NULL)(with a message) when the most recent prediction is more than 7 days oldtweetPlayoffOdds()guards against aNULLresult fromsimulatePlayoffs()with a properly formatted early returnNotes
Some functions listed in the original audit (
historicalPoints(),formatPredsForHockeyVisContest(),buildTeamColours(),buildPWHLTeamColours(),load_or_get_nst()) were retained as they are called periodically during development.