Ensure AMT is always numeric in get_initial_estimates_from_data#57
Merged
roninsightrx merged 1 commit intomainfrom Apr 1, 2026
Merged
Ensure AMT is always numeric in get_initial_estimates_from_data#57roninsightrx merged 1 commit intomainfrom
roninsightrx merged 1 commit intomainfrom
Conversation
…_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>
Contributor
There was a problem hiding this comment.
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
AMTviaas.numeric(as.character(AMT))during preprocessing inget_initial_estimates_from_data(). - Add tests verifying correct behavior when
AMTischaracterorfactor, 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 | ||
|
|
There was a problem hiding this comment.
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
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.
Summary
AMTcolumn to numeric viaas.numeric(as.character())before calculating initial estimatesas.numeric(factor)returns level codes rather than values, soas.character()is needed first to handle factor columns correctlyTest plan
devtools::test(filter = "get_initial_estimates_from_data")passes (53 tests)🤖 Generated with Claude Code