Adds gamma distribution#31
Open
kellijohnson-NOAA wants to merge 1 commit into
Open
Conversation
Bai-Li-NOAA
reviewed
Jun 12, 2026
|
|
||
| if (any(sd < 0)) { | ||
| cli::cli_abort(c( | ||
| "x" = "All values of {.var sd} must be positive", |
Collaborator
There was a problem hiding this comment.
change to "All values of {.var sd} must be non-negative".
Bai-Li-NOAA
reviewed
Jun 12, 2026
| )) | ||
| } | ||
|
|
||
| if (length(x) == 1 && length(sd) > 1) { |
Collaborator
There was a problem hiding this comment.
If sd has length 1, it's not recycled to the length of x. If a user calls sample_gamma(1:5, sd = 1), it returns a vector of identical values: 0.8361776 0.8361776 0.8361776 0.8361776 0.8361776. A possible fix from Gemini:
if (length(x) != length(sd)) {
if (length(x) == 1) {
x <- rep(x, length(sd))
} else if (length(sd) == 1) {
sd <- rep(sd, length(x))
} else {
cli::cli_abort(c(
"x" = "Length of {.var x} and {.var sd} must be compatible",
"i" = "{.var x} has length {length(x)}",
"i" = "{.var sd} has length {length(sd)}"
))
}
}
Bai-Li-NOAA
requested changes
Jun 12, 2026
Bai-Li-NOAA
left a comment
Collaborator
There was a problem hiding this comment.
Thanks, @kellijohnson-NOAA, for working on this issue. I have a few minor comments and requests regarding the recycling of sd when x is longer and some of the error messages.
| #' @description Test that sample_gamma() returns a vector when a vector is | ||
| #' passed to `x` but a single value is passed to `sd`. | ||
| expect_equal( | ||
| object = length(sample_gamma(1:5, 1)), |
Collaborator
There was a problem hiding this comment.
Add a test to check values from sample_gamma(1:5, 1).
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.
What is the feature?
How have you implemented the solution?
Does the PR impact any other area of the project, maybe another repo?
Close Add Gamma distribution sampling functionality #27