Skip to content

Commit

Permalink
Add generic alias for cal_sum()
Browse files Browse the repository at this point in the history
  • Loading branch information
Joe Roe committed Nov 1, 2024
1 parent d76bae4 commit c195f86
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 0 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ S3method(format,c14_curve_14c)
S3method(format,c14_curve_f14c)
S3method(obj_print_data,c14_cal)
S3method(pillar_shaft,c14_cal)
S3method(sum,c14_cal)
S3method(vec_ptype_abbr,c14_cal)
S3method(vec_ptype_abbr,c14_curve_14c)
S3method(vec_ptype_abbr,c14_curve_f14c)
Expand Down
6 changes: 6 additions & 0 deletions R/cal_aggregate.R
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ cal_sum <- function(x, range = cal_age_common(x), normalise = FALSE, ...) {
new_cal(list(data.frame(age = cal_age(x)[[1]], pdens = pdens_sum)))
}

#' @rdname cal_sum
#' @export
sum.c14_cal <- function(x, range = cal_age_common(x), normalise = FALSE, ...) {
cal_sum(x, range = range, normalise = normalise, ...)
}

#' Kernel density estimation of calendar probability distributions
#'
#' Aggregates calibrated radiocarbon dates and other calendar probability
Expand Down
3 changes: 3 additions & 0 deletions man/cal_sum.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions tests/testthat/test-cal_aggregate.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ test_that("cal_sum(normalise = TRUE) normalised pdens to 1", {
expect_equal(sum(cal_pdens(cal_sum(x, normalise = TRUE))[[1]]), 1)
})

test_that("sum() is an alias of cal_sum() for cal objects", {
expect_equal(sum(x), cal_sum(x))
})

test_that("cal_density() has the expected prototype", {
expect_vector(
cal_density(x),
Expand Down

0 comments on commit c195f86

Please sign in to comment.