Skip to content

Fix g.impute() NA/NaN error with study_dates_file and check_log() IDate handling#1522

Open
peterolejua wants to merge 1 commit into
wadpac:mainfrom
peterolejua:issue1508_studydates_midnight_NA
Open

Fix g.impute() NA/NaN error with study_dates_file and check_log() IDate handling#1522
peterolejua wants to merge 1 commit into
wadpac:mainfrom
peterolejua:issue1508_studydates_midnight_NA

Conversation

@peterolejua

Copy link
Copy Markdown

Fixes #1508 and #1521.

g.impute()

Guards both study-date trim branches with && \!is.na(...), so a listed start or end date that is not a midnight present in the recording falls into the existing recovery branch instead of producing r4[1:(NA - 1)] = 1 / r4[NA:nrow(r4)] = 1NA/NaN argument.

This happens because firstmidnighti = midnightsi[grep(firstmidnight, midnights)][1] (and the matching lastmidnighti line) returns NA_integer_ (length 1) when grep() finds no match, so the existing length(...) > 0 check passes and execution reaches the subscript with NA. Two situations trigger it in practice:

This PR also fixes a latent copy-paste in the first-midnight recovery else branch, which restored lastmidnighti/lastmidnight instead of firstmidnighti/firstmidnight.

check_log()

Adds log[] = lapply(log, as.character) at the top of check_log(), so study dates that data.table::fread() auto-parses as IDate are handled by the text-based date checks. The activity-log path is unaffected (it is already read with colClasses = "character"). Per @jhmigueles' suggestion in #1508.

Verification

…c#1521)

Guard both study-date trim branches in g.impute() with && \!is.na(...)
so a listed start/end date that is not a midnight present in the
recording falls into the existing recovery branch instead of producing
r4[1:(NA - 1)] -> "NA/NaN argument". Also fix the list2env() copy-paste
in the first-midnight recovery branch.

Coerce check_log() columns to character so study dates auto-parsed as
IDate by data.table::fread() are handled correctly.

Add regression tests for out-of-range study dates and check_log IDate.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.

g.impute() errors with NA/NaN argument when study_dates_file contains a start/end date that is not a midnight in the recording (regression in 3.3-5)

1 participant