Repository navigation
run.sensitivity.analysis: hoist samples loading outside variables loop (#3859) - #4107
Merged
infotroph merged 4 commits intoOct 26, 2026
Merged
Conversation
PecanProject#3859) - In modules/uncertainty/R/run.sensitivity.analysis.R, load samples.Rdata and sensitivity.samples once before the variables loop into samples_base, avoiding redundant disk reads on every variable iteration. - Use rlang::env_clone(samples_base) inside the loop to isolate per-variable modifications (e.g. Celsius unit conversions). - Rename the inner variable expression parsing to parsed_var to prevent shadowing and overwriting the loop vector variables. - Support extracting variables from settings$sensitivity.analysis when provided as a vector or multiple tags. - Add unit tests in test-run.sensitivity.analysis.R covering single-load verification and multi-variable loop preservation. - Update CHANGELOG.md and modules/uncertainty/NEWS.md.
infotroph
requested changes
Oct 21, 2026
Comment on lines
+89
to
+92
| variable <- unlist( | ||
| settings$sensitivity.analysis[names(settings$sensitivity.analysis) == "variable"], | ||
| use.names = FALSE | ||
| ) |
Member
There was a problem hiding this comment.
Revert, please. These approaches will diverge if any element has length > 1 or names of its own. It's worth asking whether or not length>1 variable specs make sense and if so whether to enforce that, but that's for a separate PR with its own tests.
Contributor
Author
There was a problem hiding this comment.
Reverted back to the original loop extraction.
- Revert unlist() variable extraction to original loop in run.sensitivity.analysis() - Keep samples environment name instead of samples_base and drop env_clone - Replace mock-based load counter test with multi-variable output verification test - Update changelog and news entries
Contributor
Author
|
Thanks for the review @infotroph! I've addressed all the feedback in the latest commit:
Ready for re-review whenever you have a moment! |
infotroph
approved these changes
Oct 26, 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.
Description
Hoists loading of
samples.Rdataandsensitivity.samplesout of thevariablesloop inrun.sensitivity.analysis(), loading them once intosamplesbefore the loop. Also resolves loop variable confusion by renaming the inner parsed expression toparsed_var <- PEcAn.utils::convert.expr(variable).Motivation and Context
Closes #3859.
Previously,
run.sensitivity.analysis()executedload(fname, envir = samples)for bothsamples.Rdataandsensitivity.samplesinsidefor (variable in variables). In multi-variable sensitivity analyses, this repeatedly re-read the same sample files from disk on every iteration.Additionally,
variables <- PEcAn.utils::convert.expr(variable)was executed inside the loop; this has been renamed toparsed_var <- PEcAn.utils::convert.expr(variable)to avoid confusion with the loop iterator.Review Time Estimate
[✓] When possible
Types of changes
[✓] Bug fix (non-breaking change which fixes an issue)
Checklist: