Skip to content

Ensure AMT is always numeric in get_initial_estimates_from_data#57

Merged
roninsightrx merged 1 commit intomainfrom
amt-numeric-coercion
Apr 1, 2026
Merged

Ensure AMT is always numeric in get_initial_estimates_from_data#57
roninsightrx merged 1 commit intomainfrom
amt-numeric-coercion

Conversation

@roninsightrx
Copy link
Copy Markdown
Contributor

Summary

  • Coerce AMT column to numeric via as.numeric(as.character()) before calculating initial estimates
  • as.numeric(factor) returns level codes rather than values, so as.character() is needed first to handle factor columns correctly
  • Adds tests covering character, factor, and a cross-type consistency check (which also caught the factor bug)

Test plan

  • devtools::test(filter = "get_initial_estimates_from_data") passes (53 tests)

🤖 Generated with Claude Code

…_data

Uses as.numeric(as.character()) to handle character and factor AMT columns
correctly — as.numeric(factor) returns level codes, not values.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

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 addresses a type-coercion bug in get_initial_estimates_from_data() by ensuring the AMT column is reliably treated as numeric before computing initial PK parameter estimates, and adds regression tests to cover common AMT input types.

Changes:

  • Coerce AMT via as.numeric(as.character(AMT)) during preprocessing in get_initial_estimates_from_data().
  • Add tests verifying correct behavior when AMT is character or factor, plus a cross-type consistency test.
  • Bump package version in DESCRIPTION.

Reviewed changes

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

File Description
R/get_initial_estimates_from_data.R Adds numeric coercion for AMT during preprocessing (and includes a minor whitespace-only change).
tests/testthat/test-get_initial_estimates_from_data.R Adds regression tests for AMT as character/factor and type-consistent outputs.
DESCRIPTION Increments package version.

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

est$V <- dose / max(obs$DV, na.rm=TRUE)
est$CL <- KEL * est$V
} else { # more crude estimation

Copy link

Copilot AI Apr 1, 2026

Choose a reason for hiding this comment

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

There is trailing whitespace on this blank line, which shows up as a changed line in the diff. Please remove the stray spaces to avoid noisy diffs and potential lint/style check failures.

Suggested change

Copilot uses AI. Check for mistakes.
@roninsightrx roninsightrx merged commit 33600fb into main Apr 1, 2026
6 checks passed
@roninsightrx roninsightrx deleted the amt-numeric-coercion branch April 1, 2026 19:05
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.

2 participants