Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RXR-372: refactor calc_ibw() #12

Merged
merged 3 commits into from
Jul 16, 2021
Merged

RXR-372: refactor calc_ibw() #12

merged 3 commits into from
Jul 16, 2021

Conversation

karawoo
Copy link
Contributor

@karawoo karawoo commented Jul 15, 2021

calc_ibw() had a number of bugs and inconsistencies in its behavior. This PR refactors it into a smaller, less complicated function with a couple of helper functions.

The main difference in behavior is that calc_ibw() no longer provides a vectorized interface. The previous vectorized operations were pretty buggy, and it's really very different data and operations that are getting used depending on the age that's provided to the function. I think this implementation is a lot cleaner and easier to maintain.

I looked at our downstream usage in our internal packages, and from what I can tell it seems we're not using the vectorized interface anyway, so I think this change shouldn't impact those packages. That said, I'm open to trying to bring back support for vector input if we think it's important (though the behavior should probably be different than before; see my comments on the RXR-372 jira ticket).

@karawoo karawoo requested a review from jasmineirx July 15, 2021 17:10
Comment on lines +73 to +76
ibw <- switch(
method_children,
"standard" = ibw_standard(age = age, height = height, sex = sex)
)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The documentation lists some other methods for children that might be implemented in the future, so I put switch() here to make it easy to add those, even though for now we only have one method.

Copy link
Contributor

@jasmineirx jasmineirx left a comment

Choose a reason for hiding this comment

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

this looks great, much more readable! One comment for a future task.

if (is.null(weight)) {
stop("Actual body weight is used as IBW for children < 1yr. Please supply a weight value.")
}
message("Note: using actual body weight as IBW for children < 1yr.")
ibw[age < 1] <- weight[age < 1]
return(weight)
Copy link
Contributor

Choose a reason for hiding this comment

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

it's a little odd that ibw is only rounded to digits digits if age >= 1. IMO rounding should happen outside of this function and not within it. However, that's better addressed in a separate change.

made an issue (RXR-405) to track.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah yeah good point. I agree rounding should happen outside the function 👍

@karawoo karawoo merged commit a3b90d5 into master Jul 16, 2021
@karawoo karawoo deleted the RXR-372 branch July 16, 2021 17:34
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.

None yet

2 participants