Refactor R package structure into domain-based modules#388
Draft
Refactor R package structure into domain-based modules#388
Conversation
Co-authored-by: henrykironde <5192965+henrykironde@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Redo earlier refactor for domain-based modules
Refactor R package structure into domain-based modules
Mar 9, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Rebases the refactor from (closed) PR #384 onto current
main. Pure structural reorganization — no logic changes, fully backward compatible.Description
Reorganizes the flat 28-file
R/directory into a domain-based module hierarchy. Splits monolithic files (utilities.Rat 7 fns,figures.Rat 940 lines) into focused modules. Extracts magic strings into constants. Adds package-level overview docs.New structure
Other changes
R/portalcasting.Rmerged intoR/portalcasting-package.R(single_PACKAGEsentinel + imports + overview docs)REFACTORING_SUMMARY.mdadded documenting what moved whereplot_forecasts_error_leadmulti-panel path referenced non-existentpevals_in$lead; corrected topevals_in$lead_time_newmoons(the column computed earlier in the same function — required to keep that code path functional)All 188 exports unchanged.
Type of change
How Has This Been Tested?
@exportdirectives confirmed present across new file locationsChecklist:
Review
@juniperlsimonis
Original prompt
Create a new draft pull request in
weecology/portalcastingto redo the earlier refactor from PR #384 (“Refactor R package structure into domain-based modules”), but rebased onto the latestmain(currentmainhead commitbee3e6ff3c3964b0b125431cd29c93dc83fe0ac1as of 2026-03-03).Context:
R/and reorganized files, added constants, and added package-level docs. Main has moved since then and now includes additional logical changes.main, resolving any conflicts with new changes since PR Refactor R package structure into domain-based modules #384.Requirements:
R/similar to PR Refactor R package structure into domain-based modules #384:R/utilities.Rsplit into:R/utils/package_utils.R(containspackage_version_finder()docs + export)R/utils/data_utils.R(containsround_na.interp(),foy(),named_null_list(),update_list(),ifnull()plus their roxygen)R/utils/file_utils.R(containsfile_ext()docs + export)R/figures.Rsplit into:R/visualization/plots_forecasts.R(containsplot_forecast_ts(),plot_forecast_point())R/visualization/plots_diagnostics.R(containsplot_forecasts_error_lead(),plot_forecasts_cov_RMSE())R/visualization/plots_covariates.R(containsplot_covariates())R/messages.R->R/utils/messaging.RR/download.R->R/data/data_download.RR/prepare_metadata.R->R/models/models_metadata.RR/models_jags.R->R/models/models_jags.RR/zip_unzip_forecasts.R->R/forecasting/forecast_storage.RR/webapp.R->R/webapp/app_launch.RR/webapp_ui.R->R/webapp/webapp_ui.RR/webapp_server.R->R/webapp/webapp_server.Rcore/constants.Rand updateforecast_storage.Rto use constants (as in PR Refactor R package structure into domain-based modules #384):DEFAULT_FORECAST_PATHFORECAST_FILE_CSV,FORECAST_FILE_YAML,FORECAST_FILE_JSONZIP_OPERATION_ZIP,ZIP_OPERATION_UNZIPAdd/update package docs file
R/portalcasting-package.R(as in PR Refactor R package structure into domain-based modules #384) if it still makes sense with current code; ensure it doesn’t break roxygen.Keep the
REFACTORING_SUMMARY.mddocument (or update it) describing what moved where.If any of the refactor changes in Refactor R package structure into domain-based modules #384 had incidental tiny fixes (e.g.,
plot_forecasts_error_leadreferencinglead_time_newmoonsinstead of a non-existentleadcolumn), only include them if they are necessary to keep code working on currentmainor if they already exist onmain. Otherwise, keep refactor-only.Deliverables:
main, with a clear description summarizing the refactor and stating it is intended as refactor-only (no functional changes).No images provided.
The following is the prior conversation context from the user's chat exploration (may be truncated):
User: We tried to refactor the package however the main branch has moved and has more logical changes, can you close this PR and then create a new PR with the same aim of refactoring
Assistant: I can help with the rebase/refactor and open a new PR, but I can’t close PR #384 from here with the tools I have (the available GitHub tools in this chat don’t support closing pull requests).
What I can do next
main(incorporating the logical changes that landed after this PR was opened).Before I proceed, I need 2 quick details
weecology/portalcastingand the target base branch ismain.If you confirm those, I’ll:
main,This pull request was created from Copilot chat.
🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.