Skip to content

fix(utils): accept NULL as synonym for NA in read.output start/end year#3987

Merged
infotroph merged 4 commits into
PecanProject:developfrom
anshul23102:fix/read-output-null-year
May 16, 2026
Merged

fix(utils): accept NULL as synonym for NA in read.output start/end year#3987
infotroph merged 4 commits into
PecanProject:developfrom
anshul23102:fix/read-output-null-year

Conversation

@anshul23102
Copy link
Copy Markdown
Contributor

@anshul23102 anshul23102 commented May 16, 2026

For non-difftime inputs, start.year and end.year used NA as the sentinel for "read all years", while variables, ncfiles, and pft.name all used NULL. This inconsistency was confusing and undocumented.

NULL is now silently converted to NA at the top of read.output() so both sentinels work identically. Default values and all existing behavior are unchanged.

Motivation and Context

Fixes #3864, flagged by @infotroph. The inconsistency made it easy to accidentally pass NULL expecting "read all years" and get unexpected behavior instead. Aligning the sentinel values makes the API consistent with every other parameter in the same function.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)

Checklist

  • All new and existing tests passed
  • I agree that PEcAn Project may distribute my contribution under BSD 3-clause license
  • I have read the CONTRIBUTING document

Fixes PecanProject#3864. Previously start.year and end.year used NA as the sentinel
for 'read all years', while variables, ncfiles, and pft.name used NULL.
This inconsistency made the API confusing.

Now NULL is silently converted to NA at the top of read.output(), so
both sentinels work. Default values and existing behavior are unchanged.

Adds a test confirming NULL and NA produce identical results.
The shared testdir accumulates files from previous tests, causing
the year count assertion to fail. Use a fresh local_tempdir() so
the test only sees exactly the two years it creates.
Regenerates the man page to reflect the NA/NULL synonym note added to
the start.year/end.year parameter documentation.
@anshul23102
Copy link
Copy Markdown
Contributor Author

Summary of changes

This PR fixes issue #3864 by accepting NULL as a synonym for NA in the start.year and end.year parameters of read.output().

What was changed

base/utils/R/read.output.R

  • Added two lines at the top of the function body that convert NULL to NA for start.year and end.year. This is consistent with how other parameters in the same function (variables, ncfiles, pft.name) use NULL to signal "use all".
  • Updated the @param documentation to mention both NA and NULL as accepted sentinel values.

base/utils/man/read.output.Rd

  • Synced the generated man page with the updated roxygen documentation (added "or NULL" to the start.year/end.year parameter description).

base/utils/tests/testthat/test-read.output.R

  • Added a new test_that block that verifies start.year = NULL, end.year = NULL gives the same result as start.year = NA, end.year = NA.
  • The test uses its own isolated nulldir <- withr::local_tempdir() rather than the shared testdir defined at the top of the file. The shared testdir accumulates .nc files across test blocks, so using it would give 3 years of data instead of the 2 that the test creates, causing a spurious failure.

CI notes

The check (check_base, ...), check (check_models, ...), and extras failures are pre-existing infrastructure issues unrelated to this PR:

All base/utils tests pass: [ FAIL 0 | WARN 0 | SKIP 1 | PASS 232 ] on both R 4.2 and R 4.4.

Copy link
Copy Markdown
Member

@infotroph infotroph left a comment

Choose a reason for hiding this comment

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

Thanks! Two quick tweaks in the inline comments, and can you please also add a bullet in NEWS.md?

Comment thread base/utils/R/read.output.R Outdated
Comment thread base/utils/R/read.output.R
Per infotroph review: change defaults from NA to NULL so the interface
is consistent with other "use all" parameters (variables, ncfiles,
pft.name). Both NULL and NA continue to work identically. Update docs
to advertise NULL as the canonical sentinel, and add a NEWS.md entry.
@anshul23102
Copy link
Copy Markdown
Contributor Author

Done - applied all three suggestions:

  • Default changed from NA to NULL for both start.year and end.year
  • Doc simplified to just say If \NULL`(dropping theNA` mention)
  • Added a ## Changed bullet to NEWS.md

Both NULL and NA still work identically internally; NULL is now the advertised default.

@infotroph infotroph enabled auto-merge May 16, 2026 07:26
@infotroph infotroph added this pull request to the merge queue May 16, 2026
Merged via the queue into PecanProject:develop with commit 672d5e4 May 16, 2026
19 of 25 checks passed
@anshul23102 anshul23102 deleted the fix/read-output-null-year branch May 16, 2026 20:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

read.output: Inconsistent start.year = NA vs variables = NULL

2 participants