-
Notifications
You must be signed in to change notification settings - Fork 10
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
Conversation
Not sure we'll do this, but it'll be easy enough
ibw <- switch( | ||
method_children, | ||
"standard" = ibw_standard(age = age, height = height, sex = sex) | ||
) |
There was a problem hiding this comment.
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.
There was a problem hiding this 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) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 👍
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).