Skip to content

fix bug that caused inf estimates for Ri or Ci ranges - #68

Merged
biwenzel merged 4 commits into
develfrom
Inf_bug
Apr 27, 2026
Merged

biwenzel merged 4 commits into
develfrom
Inf_bug

Conversation

@KarinSchork

Copy link
Copy Markdown
Member

No description provided.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR aims to prevent infinite (or otherwise invalid) Ri/Ci range estimates during the post-processing of iterateOverCi() results by filtering out unusable grid points before per-protein analysis.

Changes:

  • Add a pre-filter step in automatedAnalysisIteratedCi() to remove grid points where the error value is NA/NaN.
  • Minor roxygen/whitespace cleanups in R/06_optimization.R.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread R/06_optimization.R Outdated
Comment thread R/06_optimization.R Outdated
Comment thread R/06_optimization.R Outdated
Comment on lines +641 to +650
# filter res for potential NaNs in the error column (could occur if a Ci
# is estimated as 0)
ind_error_NA <- which(is.na(res$error))
if (length(ind_error_NA) > 0) {
if (verbose) {
message(paste0(length(ind_error_NA),
" grid points with NA or NaN error term were removed."))
}
res <- res[-ind_error_NA,]
}

Copilot AI Apr 23, 2026

Copy link

Choose a reason for hiding this comment

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

This removal only drops NA/NaN errors, but Inf/-Inf error values can still occur (e.g., from log2(0) in the error equation) and will propagate to min()/range calculations, which matches the PR’s “Inf estimates” symptom. Consider filtering on !is.finite(res$error) instead of is.na(res$error), and add a guard for the case where all rows are removed (to avoid min(numeric(0)) == Inf downstream).

Suggested change
# filter res for potential NaNs in the error column (could occur if a Ci
# is estimated as 0)
ind_error_NA <- which(is.na(res$error))
if (length(ind_error_NA) > 0) {
if (verbose) {
message(paste0(length(ind_error_NA),
" grid points with NA or NaN error term were removed."))
}
res <- res[-ind_error_NA,]
}
# filter res for non-finite values in the error column (NA, NaN, Inf,
# -Inf; could occur if a Ci is estimated as 0)
ind_error_non_finite <- which(!is.finite(res$error))
if (length(ind_error_non_finite) > 0) {
if (verbose) {
message(paste0(length(ind_error_non_finite),
" grid points with non-finite error term were removed."))
}
res <- res[-ind_error_non_finite,]
}
if (nrow(res) == 0) {
stop("All grid points were removed because the error term was non-finite.")
}

Copilot uses AI. Check for mistakes.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I would rather like to keep the results instead of stopping.

Comment thread R/06_optimization.R Outdated
Comment on lines +641 to +649
# filter res for potential NaNs in the error column (could occur if a Ci
# is estimated as 0)
ind_error_NA <- which(is.na(res$error))
if (length(ind_error_NA) > 0) {
if (verbose) {
message(paste0(length(ind_error_NA),
" grid points with NA or NaN error term were removed."))
}
res <- res[-ind_error_NA,]

Copilot AI Apr 23, 2026

Copy link

Choose a reason for hiding this comment

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

New behavior is introduced to drop grid points with non-usable error values before analysis; there are existing testthat snapshots for automatedAnalysisIteratedCi(), but nothing here asserts correct handling when res$error contains NA/NaN/Inf. Please add a test case that injects non-finite errors into a small res input and verifies the function returns finite outputs (and behaves sensibly if all grid points are filtered).

Copilot uses AI. Check for mistakes.
KarinSchork and others added 3 commits April 23, 2026 16:18
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread tests/testthat/test_06_optimization.R
Comment thread R/06_optimization.R
@biwenzel
biwenzel merged commit ed4ef2e into devel Apr 27, 2026
22 of 26 checks passed
@biwenzel
biwenzel deleted the Inf_bug branch April 27, 2026 14:26
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.

3 participants