Skip to content

Commit

Permalink
ensure point_interval(<distribution>) supports tidy eval, closes #221
Browse files Browse the repository at this point in the history
  • Loading branch information
mjskay committed Apr 6, 2024
1 parent e50c83a commit 6d1e113
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
8 changes: 5 additions & 3 deletions R/point_interval.R
Original file line number Diff line number Diff line change
Expand Up @@ -349,10 +349,12 @@ point_interval.rvar = function(
.width = .95, .point = median, .interval = qi, .simple_names = TRUE, na.rm = FALSE
) {
x = .data
# using substitute here so that names of .point / .interval are passed down correctly
eval(substitute(point_interval(
# using eval_tidy here so that names of .point / .interval are passed down correctly
eval_tidy(expr(point_interval(
tibble(.value = x), ...,
.width = .width, .point = .point, .interval = .interval, .simple_names = .simple_names, na.rm = na.rm
.width = .width,
.point = {{ .point }}, .interval = {{ .interval }},
.simple_names = .simple_names, na.rm = na.rm
)))
}

Expand Down
7 changes: 7 additions & 0 deletions tests/testthat/test.point_interval.R
Original file line number Diff line number Diff line change
Expand Up @@ -734,6 +734,13 @@ test_that("flattened indices retain index order", {

})

test_that("automatic partial evaluation works with distributional objects", {
expect_equal(
point_interval(.point = mean)(dist_normal()),
point_interval(dist_normal(), .point = mean)
)
})


# 100% intervals ----------------------------------------------------------

Expand Down

0 comments on commit 6d1e113

Please sign in to comment.