Skip to content

Commit

Permalink
Namespace prefix all almanac class names
Browse files Browse the repository at this point in the history
  • Loading branch information
DavisVaughan committed Apr 6, 2023
1 parent 1b5555b commit 64d692e
Show file tree
Hide file tree
Showing 17 changed files with 70 additions and 67 deletions.
32 changes: 16 additions & 16 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
# Generated by roxygen2: do not edit by hand

S3method(print,radjusted)
S3method(print,rcustom)
S3method(print,rintersect)
S3method(print,rrule)
S3method(print,rsetdiff)
S3method(print,runion)
S3method(print,almanac_radjusted)
S3method(print,almanac_rcustom)
S3method(print,almanac_rintersect)
S3method(print,almanac_rrule)
S3method(print,almanac_rsetdiff)
S3method(print,almanac_runion)
S3method(rschedule_events,almanac_radjusted)
S3method(rschedule_events,almanac_rcustom)
S3method(rschedule_events,almanac_rintersect)
S3method(rschedule_events,almanac_rrule)
S3method(rschedule_events,almanac_rschedule)
S3method(rschedule_events,almanac_rsetdiff)
S3method(rschedule_events,almanac_runion)
S3method(rschedule_events,default)
S3method(rschedule_events,radjusted)
S3method(rschedule_events,rcustom)
S3method(rschedule_events,rintersect)
S3method(rschedule_events,rrule)
S3method(rschedule_events,rschedule)
S3method(rschedule_events,rsetdiff)
S3method(rschedule_events,runion)
S3method(rset_restore,rintersect)
S3method(rset_restore,rsetdiff)
S3method(rset_restore,runion)
S3method(rset_restore,almanac_rintersect)
S3method(rset_restore,almanac_rsetdiff)
S3method(rset_restore,almanac_runion)
S3method(vec_arith,almanac_stepper)
S3method(vec_arith.Date,almanac_stepper)
S3method(vec_arith.almanac_stepper,Date)
Expand Down
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# almanac (development version)

* All almanac class names are now prefixed with `almanac_*` to avoid potential
clashes with other packages.

* The `recur_with_week_start()` argument `wday` has been renamed to `day`.

* The following developer facing functions have been removed because they are
Expand Down
8 changes: 4 additions & 4 deletions R/almanac-deprecated.R
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ check_rset <- function(x,
call = caller_env()) {
check_inherits(
x = x,
what = "rset",
what = "almanac_rset",
allow_null = allow_null,
arg = arg,
call = call
Expand All @@ -273,7 +273,7 @@ rset_restore <- function(x, to) {
}

#' @export
rset_restore.rintersect <- function(x, to) {
rset_restore.almanac_rintersect <- function(x, to) {
new_rintersect(
rschedules = x$rschedules,
rdates = x$rdates,
Expand All @@ -282,7 +282,7 @@ rset_restore.rintersect <- function(x, to) {
}

#' @export
rset_restore.runion <- function(x, to) {
rset_restore.almanac_runion <- function(x, to) {
new_runion(
rschedules = x$rschedules,
rdates = x$rdates,
Expand All @@ -291,7 +291,7 @@ rset_restore.runion <- function(x, to) {
}

#' @export
rset_restore.rsetdiff <- function(x, to) {
rset_restore.almanac_rsetdiff <- function(x, to) {
new_rsetdiff(
rschedules = x$rschedules,
rdates = x$rdates,
Expand Down
6 changes: 3 additions & 3 deletions R/radjusted.R
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ radjusted <- function(rschedule, adjust_on, adjustment) {
# ------------------------------------------------------------------------------

#' @export
print.radjusted <- function(x, ...) {
print.almanac_radjusted <- function(x, ...) {
cli::cli_text("<radjusted>")

cli_indented()
Expand All @@ -82,7 +82,7 @@ print.radjusted <- function(x, ...) {
# ------------------------------------------------------------------------------

#' @export
rschedule_events.radjusted <- function(x) {
rschedule_events.almanac_radjusted <- function(x) {
x$cache$get_events()
}

Expand All @@ -104,7 +104,7 @@ new_radjusted <- function(rschedule, adjust_on, adjustment) {
adjust_on = adjust_on,
adjustment = adjustment,
cache = cache,
class = "radjusted"
class = "almanac_radjusted"
)
}

Expand Down
6 changes: 3 additions & 3 deletions R/rcustom.R
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ rcustom <- function(events) {

new_rcustom <- function(events, ..., class = character()) {
check_date(events)
new_rschedule(events = events, ..., class = c(class, "rcustom"))
new_rschedule(events = events, ..., class = c(class, "almanac_rcustom"))
}

#' @export
print.rcustom <- function(x, ...) {
print.almanac_rcustom <- function(x, ...) {
events <- rcustom_events(x)
events <- as.character(events)

Expand All @@ -63,7 +63,7 @@ print.rcustom <- function(x, ...) {
}

#' @export
rschedule_events.rcustom <- function(x) {
rschedule_events.almanac_rcustom <- function(x) {
rcustom_events(x)
}

Expand Down
2 changes: 1 addition & 1 deletion R/rrule-print.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#' @export
print.rrule <- function(x, ...) {
print.almanac_rrule <- function(x, ...) {
cli::cli_text("<rrule>")
cli::cli_ul(format_body(x))
invisible(x)
Expand Down
8 changes: 4 additions & 4 deletions R/rrule.R
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ yearly <- function(since = "1900-01-01", until = "2100-01-01") {
# ------------------------------------------------------------------------------

#' @export
rschedule_events.rrule <- function(x) {
rschedule_events.almanac_rrule <- function(x) {
x$cache$get_events()
}

Expand Down Expand Up @@ -172,14 +172,14 @@ new_rrule <- function(since = as.Date("1900-01-01"),
new_rschedule(
rules = rules,
cache = cache,
class = "rrule"
class = "almanac_rrule"
)
}

# ------------------------------------------------------------------------------

is_rrule <- function(x) {
inherits(x, "rrule")
inherits(x, "almanac_rrule")
}

all_are_rrules <- function(x) {
Expand All @@ -193,7 +193,7 @@ check_rrule <- function(x,
call = caller_env()) {
check_inherits(
x = x,
what = "rrule",
what = "almanac_rrule",
allow_null = allow_null,
arg = arg,
call = call
Expand Down
10 changes: 5 additions & 5 deletions R/rschedule.R
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ new_rschedule <- function(..., class) {
abort("`...` must have named elements.")
}

structure(data, class = c(class, "rschedule"))
structure(data, class = c(class, "almanac_rschedule"))
}

# ------------------------------------------------------------------------------
Expand All @@ -73,14 +73,14 @@ rschedule_events.default <- function(x) {
}

#' @export
rschedule_events.rschedule <- function(x) {
cli::cli_abort("<rschedule> subclasses must provide their own `rschedule_events()` method.")
rschedule_events.almanac_rschedule <- function(x) {
cli::cli_abort("<almanac_rschedule> subclasses must provide their own `rschedule_events()` method.")
}

# ------------------------------------------------------------------------------

is_rschedule <- function(x) {
inherits(x, "rschedule")
inherits(x, "almanac_rschedule")
}

check_rschedule <- function(x,
Expand All @@ -90,7 +90,7 @@ check_rschedule <- function(x,
call = caller_env()) {
check_inherits(
x = x,
what = "rschedule",
what = "almanac_rschedule",
allow_null = allow_null,
arg = arg,
call = call
Expand Down
20 changes: 10 additions & 10 deletions R/rset.R
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ new_runion <- function(rschedules = list(),
exdates = exdates,
cache = cache,
...,
class = c(class, "runion")
class = c(class, "almanac_runion")
)
}

Expand Down Expand Up @@ -110,7 +110,7 @@ new_rintersect <- function(rschedules = list(),
exdates = exdates,
cache = cache,
...,
class = c(class, "rintersect")
class = c(class, "almanac_rintersect")
)
}

Expand Down Expand Up @@ -139,7 +139,7 @@ new_rsetdiff <- function(rschedules = list(),
exdates = exdates,
cache = cache,
...,
class = c(class, "rsetdiff")
class = c(class, "almanac_rsetdiff")
)
}

Expand All @@ -166,41 +166,41 @@ new_rset <- function(rschedules = list(),
rdates = rdates,
exdates = exdates,
...,
class = c(class, "rset")
class = c(class, "almanac_rset")
)
}

# ------------------------------------------------------------------------------

#' @export
rschedule_events.runion <- function(x) {
rschedule_events.almanac_runion <- function(x) {
x$cache$get_events()
}

#' @export
rschedule_events.rintersect <- function(x) {
rschedule_events.almanac_rintersect <- function(x) {
x$cache$get_events()
}

#' @export
rschedule_events.rsetdiff <- function(x) {
rschedule_events.almanac_rsetdiff <- function(x) {
x$cache$get_events()
}

# ------------------------------------------------------------------------------

#' @export
print.runion <- function(x, ...) {
print.almanac_runion <- function(x, ...) {
print_rset(x, "runion")
}

#' @export
print.rintersect <- function(x, ...) {
print.almanac_rintersect <- function(x, ...) {
print_rset(x, "rintersect")
}

#' @export
print.rsetdiff <- function(x, ...) {
print.almanac_rsetdiff <- function(x, ...) {
print_rset(x, "rsetdiff")
}

Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/_snaps/radjusted.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
radjusted(1, daily(), adj_none)
Condition
Error in `new_radjusted()`:
! `rschedule` must be a <rschedule>, not the number 1.
! `rschedule` must be a <almanac_rschedule>, not the number 1.

# adjust_on is checked

Code
radjusted(daily(), 1, adj_none)
Condition
Error in `new_radjusted()`:
! `adjust_on` must be a <rschedule>, not the number 1.
! `adjust_on` must be a <almanac_rschedule>, not the number 1.

# adjustment is checked

Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/_snaps/rrule.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@
check_rrule(1)
Condition
Error:
! `1` must be a <rrule>, not the number 1.
! `1` must be a <almanac_rrule>, not the number 1.

---

Code
check_rrule(1, allow_null = TRUE)
Condition
Error:
! `1` must be a <rrule> or `NULL`, not the number 1.
! `1` must be a <almanac_rrule> or `NULL`, not the number 1.

2 changes: 1 addition & 1 deletion tests/testthat/_snaps/rschedule.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,5 @@
rschedule_events(x)
Condition
Error in `rschedule_events()`:
! <rschedule> subclasses must provide their own `rschedule_events()` method.
! <almanac_rschedule> subclasses must provide their own `rschedule_events()` method.

2 changes: 1 addition & 1 deletion tests/testthat/_snaps/stepper.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
new_stepper(rschedule = 1)
Condition
Error in `new_stepper()`:
! `rschedule` must be a <rschedule>, not the number 1.
! `rschedule` must be a <almanac_rschedule>, not the number 1.

# default method error is thrown

Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-radjusted.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

test_that("can create an radjusted rschedule", {
x <- radjusted(daily(), daily(), adj_none)
expect_s3_class(x, c("radjusted", "rschedule"))
expect_s3_class(x, c("almanac_radjusted", "almanac_rschedule"))
})

test_that("radjusted adjusts dates", {
Expand Down
8 changes: 4 additions & 4 deletions tests/testthat/test-rrule.R
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
test_that("can construct a base recurrence rule", {
expect_s3_class(daily(), "rrule")
expect_s3_class(weekly(), "rrule")
expect_s3_class(monthly(), "rrule")
expect_s3_class(yearly(), "rrule")
expect_s3_class(daily(), "almanac_rrule")
expect_s3_class(weekly(), "almanac_rrule")
expect_s3_class(monthly(), "almanac_rrule")
expect_s3_class(yearly(), "almanac_rrule")
})

test_that("can use a character `since` date", {
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-rschedule.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ test_that("class is required", {

test_that("can create rschedule subclasses", {
x <- new_rschedule(x = 1, class = "foobar")
expect_identical(x, structure(list(x = 1), class = c("foobar", "rschedule")))
expect_identical(x, structure(list(x = 1), class = c("foobar", "almanac_rschedule")))
})

# ------------------------------------------------------------------------------
Expand Down
Loading

0 comments on commit 64d692e

Please sign in to comment.