R Under development (unstable) (2026-11-11 r90876) -- "Unsuffered Consequences" Copyright (C) 2026 The R Foundation for Statistical Computing Platform: x86_64-pc-linux-gnu R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. Natural language support but running in an English locale R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. > pkgname <- "grates" > source(file.path(R.home("share"), "R", "examples-header.R")) > options(warn = 1) > library('grates') > > base::assign(".oldSearch", base::search(), pos = 'CheckExEnv') > base::assign(".old_wd", base::getwd(), pos = 'CheckExEnv') > cleanEx() > nameEx("boundaries") > ### * boundaries > > flush(stderr()); flush(stdout()) > > ### Name: boundaries > ### Title: Access the bounding dates of a grates object > ### Aliases: boundaries date_start date_end > > ### ** Examples > > dates <- as.Date("2020-01-01") + 1:9 > week <- as_isoweek(dates) > date_start(week) [1] "2019-12-30" "2019-12-30" "2019-12-30" "2019-12-30" "2020-01-06" [6] "2020-01-06" "2020-01-06" "2020-01-06" "2020-01-06" > date_end(week) [1] "2020-01-05" "2020-01-05" "2020-01-05" "2020-01-05" "2020-01-12" [6] "2020-01-12" "2020-01-12" "2020-01-12" "2020-01-12" > > period <- as_period(dates, n = 3) > date_start(period) [1] "2020-01-02" "2020-01-02" "2020-01-02" "2020-01-05" "2020-01-05" [6] "2020-01-05" "2020-01-08" "2020-01-08" "2020-01-08" > date_end(period) [1] "2020-01-04" "2020-01-04" "2020-01-04" "2020-01-07" "2020-01-07" [6] "2020-01-07" "2020-01-10" "2020-01-10" "2020-01-10" > > > > > cleanEx() > nameEx("epiweek_class") > ### * epiweek_class > > flush(stderr()); flush(stdout()) > > ### Name: epiweek_class > ### Title: Epiweek class > ### Aliases: epiweek_class epiweek as_epiweek as_epiweek.default > ### as_epiweek.Date as_epiweek.POSIXt as_epiweek.character > ### as_epiweek.factor new_epiweek is_epiweek > > ### ** Examples > > > # date coercion > as_epiweek(Sys.Date()) [1] "2026-W45" > > # POSIXt coercion > as_epiweek(as.POSIXct("2019-03-04 01:01:01", tz = "America/New_York")) [1] "2019-W10" > > # character coercion assumes date input by default > as_epiweek("2019-05-03") [1] "2019-W18" > > # character coercion can handle YYYY-Wxx format too > as_epiweek("2019-W12", format = "yearweek") [1] "2019-W12" > > # construction > epiweek(year = 2000, week = 3) [1] "2000-W03" > > # direct construction > stopifnot( + identical( + new_epiweek(0:1), + as_epiweek("1970-01-04") + 0:1 + ) + ) > > > > cleanEx() > nameEx("get_interval_duration") > ### * get_interval_duration > > flush(stderr()); flush(stdout()) > > ### Name: get_interval_duration > ### Title: The number of days covered > ### Aliases: get_interval_duration > > ### ** Examples > > # The following should be TRUE > identical( + get_interval_duration(yearmonth(2020, 1:3)), + c(31, 29, 31) + ) [1] TRUE > > > > > cleanEx() > nameEx("grapes-during-grapes") > ### * grapes-during-grapes > > flush(stderr()); flush(stdout()) > > ### Name: %during% > ### Title: Is a date covered by a grouped date > ### Aliases: %during% > > ### ** Examples > > > dates <- as.Date("2020-01-01") + 1:10 > week <- as_isoweek(dates) > dates[1] %during% week [1] TRUE TRUE TRUE TRUE FALSE FALSE FALSE FALSE FALSE FALSE > > period <- as_period(dates, n = 3) > dates[10] %during% period [1] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE TRUE > > > > > cleanEx() > nameEx("grouped_date_accessors") > ### * grouped_date_accessors > > flush(stderr()); flush(stdout()) > > ### Name: grouped_date_accessors > ### Title: Accessors for grate objects > ### Aliases: grouped_date_accessors get_firstday get_firstday.default > ### get_firstday.grates_yearweek_monday > ### get_firstday.grates_yearweek_tuesday > ### get_firstday.grates_yearweek_wednesday > ### get_firstday.grates_yearweek_thursday > ### get_firstday.grates_yearweek_friday > ### get_firstday.grates_yearweek_saturday > ### get_firstday.grates_yearweek_sunday get_firstday.grates_isoweek > ### get_firstday.grates_epiweek get_week get_week.default > ### get_week.grates_yearweek get_week.grates_epiweek > ### get_week.grates_isoweek get_year get_year.grates_yearweek > ### get_year.grates_epiweek get_year.grates_isoweek > ### get_year.grates_yearmonth get_year.grates_yearquarter > ### get_year.grates_year get_n get_n.default get_n.grates_month > ### get_n.grates_period get_n.grates_int_period get_offset > ### get_offset.default get_offset.grates_period > > ### ** Examples > > dates <- as.Date("2020-01-01") + 1:14 > dat <- as_isoweek(dates) > get_week(dat) [1] 1 1 1 1 2 2 2 2 2 2 2 3 3 3 > get_year(dat) [1] 2020 2020 2020 2020 2020 2020 2020 2020 2020 2020 2020 2020 2020 2020 > > > > > cleanEx() > nameEx("int_period_class") > ### * int_period_class > > flush(stderr()); flush(stdout()) > > ### Name: int_period_class > ### Title: Integer-period class (Experimental) > ### Aliases: int_period_class as_int_period.default as_int_period.integer > ### as_int_period.double new_int_period is_int_period as_int_period > > ### ** Examples > > > # coercion > as_int_period(1:10, n = 3) [1] [0, 2] [0, 2] [3, 5] [3, 5] [3, 5] [6, 8] [6, 8] [6, 8] [9, 11] [10] [9, 11] > > # direct construction > stopifnot( + identical( + as_int_period(1:10, n = 3), + new_int_period(c(0, 0, 1, 1, 1, 2, 2, 2, 3, 3), n = 3) + ) + ) > > > > > > > cleanEx() > nameEx("isoweek_class") > ### * isoweek_class > > flush(stderr()); flush(stdout()) > > ### Name: isoweek_class > ### Title: ISO Week class > ### Aliases: isoweek_class isoweek as_isoweek as_isoweek.default > ### as_isoweek.Date as_isoweek.POSIXt as_isoweek.character > ### as_isoweek.factor new_isoweek is_isoweek > > ### ** Examples > > > # date coercion > as_isoweek(Sys.Date()) [1] "2026-W46" > > # POSIXt coercion > as_isoweek(as.POSIXct("2019-03-04 01:01:01", tz = "America/New_York")) [1] "2019-W10" > > # character coercion assumes date input by default > as_isoweek("2019-05-03") [1] "2019-W18" > > # character coercion can handle YYYY-Wxx format too > as_isoweek("2019-W12", format = "yearweek") [1] "2019-W12" > > # construction > isoweek(year = 2000, week = 3) [1] "2000-W03" > > # direct construction > stopifnot( + identical( + new_isoweek(0:1), + as_isoweek("1969-12-29") + 0:1 + ) + ) > > > > > cleanEx() > nameEx("month_class") > ### * month_class > > flush(stderr()); flush(stdout()) > > ### Name: month_class > ### Title: Month class > ### Aliases: month_class as_month as_month.default as_month.Date > ### as_month.POSIXt as_month.character as_month.factor new_month is_month > > ### ** Examples > > > # date coercion > as_month(Sys.Date(), n = 2) [1] "2026-Nov to 2026-Dec" > > # character coercion > as_month("2019-05-03", n = 4) [1] "2019-May to 2019-Aug" > > # POSIXt coercion > as_month(as.POSIXct("2019-03-04 01:01:01", tz = "America/New_York"), n = 2) [1] "2019-Mar to 2019-Apr" > > # direct construction > d <- seq.Date(from = as.Date("1970-03-01"), by = "2 month", length.out = 10) > stopifnot( + identical( + as_month(d, n = 2), + new_month(1:10, 2) + ) + ) > > > > > cleanEx() > nameEx("period_class") > ### * period_class > > flush(stderr()); flush(stdout()) > > ### Name: period_class > ### Title: Period class > ### Aliases: period_class as_period as_period.default as_period.Date > ### as_period.POSIXt as_period.character as_period.factor new_period > ### is_period > > ### ** Examples > > > # coercion from date > dat <- as.Date("2012-12-01") > as_period(dat + 0:3, n = 2, offset = dat) [1] "2012-12-01 to 2012-12-02" "2012-12-01 to 2012-12-02" [3] "2012-12-03 to 2012-12-04" "2012-12-03 to 2012-12-04" > > # direct construction > new_period(1:10) [1] "1970-01-02" "1970-01-03" "1970-01-04" "1970-01-05" "1970-01-06" [6] "1970-01-07" "1970-01-08" "1970-01-09" "1970-01-10" "1970-01-11" > > > > > cleanEx() > nameEx("scale_x_grates_epiweek") > ### * scale_x_grates_epiweek > > flush(stderr()); flush(stdout()) > > ### Name: scale_x_grates_epiweek > ### Title: Epiweek scale > ### Aliases: scale_x_grates_epiweek > > ### ** Examples > > ## Don't show: > if (requireNamespace("outbreaks") && requireNamespace("ggplot2")) withAutoprint({ # examplesIf + ## End(Don't show) + + # use simulated linelist data from the outbreaks package + linelist <- outbreaks::ebola_sim_clean$linelist + x <- as_epiweek(linelist$date_of_infection) + dat <- aggregate(list(cases = x), by = list(week = x), FUN = length) + + # plot the output + (week_plot <- + ggplot2::ggplot(dat, ggplot2::aes(week, cases)) + + ggplot2::geom_col(width = 1, colour = "white") + + ggplot2::theme_bw()) + + # We can have non-centred date labels on the x_axis by using the + # associated scale function and explicitly specifying a format for + # the date labels: + week_plot + scale_x_grates_epiweek(format = "%Y-%m-%d") + ## Don't show: + }) # examplesIf Loading required namespace: outbreaks Loading required namespace: ggplot2 > linelist <- outbreaks::ebola_sim_clean$linelist > x <- as_epiweek(linelist$date_of_infection) grates.c:37:60: runtime error: nan is outside the range of representable values of type 'int' #0 0x7faf97270ae5 in as_grouped_week_from_date /data/localhost/ripley/R/packages/tests-clang-UBSAN/grates/src/grates.c:37:60 #1 0x55886a70ab92 in R_doDotCall (/data/localhost/ripley/R/R-clang/bin/exec/R+0x90b92) #2 0x55886a756e9c in bcEval_loop eval.c #3 0x55886a744bfb in bcEval eval.c #4 0x55886a7443b4 in Rf_eval (/data/localhost/ripley/R/R-clang/bin/exec/R+0xca3b4) #5 0x55886a75c9c8 in R_execClosure eval.c #6 0x55886a75be9a in applyClosure_core eval.c #7 0x55886a7452c6 in Rf_applyClosure (/data/localhost/ripley/R/R-clang/bin/exec/R+0xcb2c6) #8 0x55886a7a9681 in dispatchMethod objects.c #9 0x55886a7a90a8 in Rf_usemethod (/data/localhost/ripley/R/R-clang/bin/exec/R+0x12f0a8) #10 0x55886a7a9bde in do_usemethod (/data/localhost/ripley/R/R-clang/bin/exec/R+0x12fbde) #11 0x55886a74b775 in bcEval_loop eval.c #12 0x55886a744bfb in bcEval eval.c #13 0x55886a7443b4 in Rf_eval (/data/localhost/ripley/R/R-clang/bin/exec/R+0xca3b4) #14 0x55886a75c9c8 in R_execClosure eval.c #15 0x55886a75be9a in applyClosure_core eval.c #16 0x55886a7452c6 in Rf_applyClosure (/data/localhost/ripley/R/R-clang/bin/exec/R+0xcb2c6) #17 0x55886a744807 in Rf_eval (/data/localhost/ripley/R/R-clang/bin/exec/R+0xca807) #18 0x55886a761d27 in do_set (/data/localhost/ripley/R/R-clang/bin/exec/R+0xe7d27) #19 0x55886a7445df in Rf_eval (/data/localhost/ripley/R/R-clang/bin/exec/R+0xca5df) #20 0x55886a763567 in do_eval (/data/localhost/ripley/R/R-clang/bin/exec/R+0xe9567) #21 0x55886a74b517 in bcEval_loop eval.c #22 0x55886a744bfb in bcEval eval.c #23 0x55886a7443b4 in Rf_eval (/data/localhost/ripley/R/R-clang/bin/exec/R+0xca3b4) #24 0x55886a744e53 in forcePromise eval.c #25 0x55886a74447d in Rf_eval (/data/localhost/ripley/R/R-clang/bin/exec/R+0xca47d) #26 0x55886a763666 in do_withVisible (/data/localhost/ripley/R/R-clang/bin/exec/R+0xe9666) #27 0x55886a7a73c7 in do_internal (/data/localhost/ripley/R/R-clang/bin/exec/R+0x12d3c7) #28 0x55886a74b775 in bcEval_loop eval.c #29 0x55886a744bfb in bcEval eval.c #30 0x55886a7443b4 in Rf_eval (/data/localhost/ripley/R/R-clang/bin/exec/R+0xca3b4) #31 0x55886a75c9c8 in R_execClosure eval.c #32 0x55886a75be9a in applyClosure_core eval.c #33 0x55886a7452c6 in Rf_applyClosure (/data/localhost/ripley/R/R-clang/bin/exec/R+0xcb2c6) #34 0x55886a744807 in Rf_eval (/data/localhost/ripley/R/R-clang/bin/exec/R+0xca807) #35 0x55886a7445df in Rf_eval (/data/localhost/ripley/R/R-clang/bin/exec/R+0xca5df) #36 0x55886a792387 in Rf_ReplIteration (/data/localhost/ripley/R/R-clang/bin/exec/R+0x118387) #37 0x55886a793e7e in run_Rmainloop (/data/localhost/ripley/R/R-clang/bin/exec/R+0x119e7e) #38 0x55886a793eea in Rf_mainloop (/data/localhost/ripley/R/R-clang/bin/exec/R+0x119eea) #39 0x55886a67bdb7 in main (/data/localhost/ripley/R/R-clang/bin/exec/R+0x1db7) #40 0x7faf9740a680 in __libc_start_call_main (/lib64/libc.so.6+0x3680) (BuildId: 85075e2ae2e13352a1413d41c327dacf6461526c) #41 0x7faf9740a797 in __libc_start_main@GLIBC_2.2.5 (/lib64/libc.so.6+0x3797) (BuildId: 85075e2ae2e13352a1413d41c327dacf6461526c) #42 0x55886a67bcd4 in _start (/data/localhost/ripley/R/R-clang/bin/exec/R+0x1cd4) SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior grates.c:37:60 > dat <- aggregate(list(cases = x), by = list(week = x), FUN = length) > (week_plot <- ggplot2::ggplot(dat, ggplot2::aes(week, cases)) + ggplot2::geom_col(width = 1, + colour = "white") + ggplot2::theme_bw()) > week_plot + scale_x_grates_epiweek(format = "%Y-%m-%d") > ## End(Don't show) > > > > cleanEx() > nameEx("scale_x_grates_isoweek") > ### * scale_x_grates_isoweek > > flush(stderr()); flush(stdout()) > > ### Name: scale_x_grates_isoweek > ### Title: Isoweek scale > ### Aliases: scale_x_grates_isoweek > > ### ** Examples > > ## Don't show: > if (requireNamespace("outbreaks") && requireNamespace("ggplot2")) withAutoprint({ # examplesIf + ## End(Don't show) + + # use simulated linelist data from the outbreaks package + linelist <- outbreaks::ebola_sim_clean$linelist + x <- as_isoweek(linelist$date_of_infection) + dat <- aggregate(list(cases = x), by = list(week = x), FUN = length) + + # plot the output + (week_plot <- + ggplot2::ggplot(dat, ggplot2::aes(week, cases)) + + ggplot2::geom_col(width = 1, colour = "white") + + ggplot2::theme_bw()) + + # We can have non-centred date labels on the x_axis by using the + # associated scale function and explicitly specifying a format for + # the date labels: + week_plot + scale_x_grates_isoweek(format = "%Y-%m-%d") + ## Don't show: + }) # examplesIf > linelist <- outbreaks::ebola_sim_clean$linelist > x <- as_isoweek(linelist$date_of_infection) > dat <- aggregate(list(cases = x), by = list(week = x), FUN = length) > (week_plot <- ggplot2::ggplot(dat, ggplot2::aes(week, cases)) + ggplot2::geom_col(width = 1, + colour = "white") + ggplot2::theme_bw()) > week_plot + scale_x_grates_isoweek(format = "%Y-%m-%d") > ## End(Don't show) > > > > cleanEx() > nameEx("scale_x_grates_month") > ### * scale_x_grates_month > > flush(stderr()); flush(stdout()) > > ### Name: scale_x_grates_month > ### Title: Month scale > ### Aliases: scale_x_grates_month > > ### ** Examples > > ## Don't show: > if (requireNamespace("outbreaks") && requireNamespace("ggplot2")) withAutoprint({ # examplesIf + ## End(Don't show) + + # use simulated linelist data from the outbreaks package + linelist <- outbreaks::ebola_sim_clean$linelist + + # calculate the bimonthly number of cases + x <- as_month(linelist$date_of_infection, n = 2) + (dat <- aggregate(list(cases = x), by = list(group = x), FUN = length)) + + # by default lower date bounds are used for the x axis + (bimonth_plot <- + ggplot2::ggplot(dat, ggplot2::aes(group, cases)) + + ggplot2::geom_col(width = 1, colour = "white") + + ggplot2::theme_bw() + + ggplot2::theme( + axis.text.x = ggplot2::element_text( + angle = 45, + hjust = 1 + ) + ) + + ggplot2::xlab("")) + + # To obtain centred labels you must explicitly set the format to NULL + # in the scale: + bimonth_plot + scale_x_grates_month(format = NULL, n = 2) + ## Don't show: + }) # examplesIf > linelist <- outbreaks::ebola_sim_clean$linelist > x <- as_month(linelist$date_of_infection, n = 2) > (dat <- aggregate(list(cases = x), by = list(group = x), FUN = length)) group cases 1 2014-Mar to 2014-Apr 7 2 2014-May to 2014-Jun 137 3 2014-Jul to 2014-Aug 636 4 2014-Sep to 2014-Oct 1532 5 2014-Nov to 2014-Dec 755 6 2015-Jan to 2015-Feb 450 7 2015-Mar to 2015-Apr 225 > (bimonth_plot <- ggplot2::ggplot(dat, ggplot2::aes(group, cases)) + ggplot2::geom_col(width = 1, + colour = "white") + ggplot2::theme_bw() + ggplot2::theme(axis.text.x = ggplot2::element_text(angle = 45, + hjust = 1)) + ggplot2::xlab("")) > bimonth_plot + scale_x_grates_month(format = NULL, n = 2) > ## End(Don't show) > > > > cleanEx() > nameEx("scale_x_grates_period") > ### * scale_x_grates_period > > flush(stderr()); flush(stdout()) > > ### Name: scale_x_grates_period > ### Title: Period scale > ### Aliases: scale_x_grates_period > > ### ** Examples > > ## Don't show: > if (requireNamespace("outbreaks") && requireNamespace("ggplot2")) withAutoprint({ # examplesIf + ## End(Don't show) + + # use simulated linelist data from the outbreaks package + linelist <- outbreaks::ebola_sim_clean$linelist + + # Calculate the total of infections across 14 day periods offset from + # the first date + x <- linelist$date_of_infection + x <- as_period(x, n = 14, offset = min(x, na.rm = TRUE)) + dat <- aggregate(list(cases = x), by = list(period = x), FUN = length) + head(dat) + + (period_plot <- ggplot2::ggplot(dat, ggplot2::aes(period, cases)) + + ggplot2::geom_col(width = 1, colour = "white") + + ggplot2::theme_bw() + + ggplot2::theme( + axis.text.x = ggplot2::element_text( + angle = 45, + hjust = 1 + ) + ) + + ggplot2::xlab("")) + + # To change defaults we must explicitly state the value of n and + # offset when calling the scale function + period_plot + scale_x_grates_period( + n.breaks = 2, + n = 14, + offset = min(x, na.rm = TRUE) + ) + ## Don't show: + }) # examplesIf > linelist <- outbreaks::ebola_sim_clean$linelist > x <- linelist$date_of_infection > x <- as_period(x, n = 14, offset = min(x, na.rm = TRUE)) > dat <- aggregate(list(cases = x), by = list(period = x), FUN = length) > head(dat) period cases 1 2014-03-19 to 2014-04-01 1 2 2014-04-02 to 2014-04-15 1 3 2014-04-16 to 2014-04-29 5 4 2014-04-30 to 2014-05-13 22 5 2014-05-14 to 2014-05-27 28 6 2014-05-28 to 2014-06-10 31 > (period_plot <- ggplot2::ggplot(dat, ggplot2::aes(period, cases)) + ggplot2::geom_col(width = 1, + colour = "white") + ggplot2::theme_bw() + ggplot2::theme(axis.text.x = ggplot2::element_text(angle = 45, + hjust = 1)) + ggplot2::xlab("")) > period_plot + scale_x_grates_period(n.breaks = 2, n = 14, offset = min(x, + na.rm = TRUE)) > ## End(Don't show) > > > > cleanEx() > nameEx("scale_x_grates_year") > ### * scale_x_grates_year > > flush(stderr()); flush(stdout()) > > ### Name: scale_x_grates_year > ### Title: Year scale > ### Aliases: scale_x_grates_year > > ### ** Examples > > ## Don't show: > if (requireNamespace("outbreaks") && requireNamespace("ggplot2")) withAutoprint({ # examplesIf + ## End(Don't show) + + # use simulated linelist data from the outbreaks package + linelist <- outbreaks::ebola_sim_clean$linelist + + # calculate yearly cases by date of infection + x <- as_year(linelist$date_of_infection) + (dat <- aggregate(list(cases = x), by = list(year = x), FUN = length)) + + # by default labels are centred + (year_plot <- + ggplot2::ggplot(dat, ggplot2::aes(year, cases)) + + ggplot2::geom_col(width = 1, colour = "white") + + ggplot2::theme_bw() + + ggplot2::xlab("")) + + # To obtain centred labels you must explicitly set a date format + # in the scale: + year_plot + scale_x_grates_year(format = "%Y-%m-%d") + + ## Don't show: + }) # examplesIf > linelist <- outbreaks::ebola_sim_clean$linelist > x <- as_year(linelist$date_of_infection) > (dat <- aggregate(list(cases = x), by = list(year = x), FUN = length)) year cases 1 2014 3067 2 2015 675 > (year_plot <- ggplot2::ggplot(dat, ggplot2::aes(year, cases)) + ggplot2::geom_col(width = 1, + colour = "white") + ggplot2::theme_bw() + ggplot2::xlab("")) > year_plot + scale_x_grates_year(format = "%Y-%m-%d") > ## End(Don't show) > > > > cleanEx() > nameEx("scale_x_grates_yearquarter") > ### * scale_x_grates_yearquarter > > flush(stderr()); flush(stdout()) > > ### Name: scale_x_grates_yearquarter > ### Title: Yearquarter scale > ### Aliases: scale_x_grates_yearquarter > > ### ** Examples > > ## Don't show: > if (requireNamespace("outbreaks") && requireNamespace("ggplot2")) withAutoprint({ # examplesIf + ## End(Don't show) + + # use simulated linelist data from the outbreaks package + linelist <- outbreaks::ebola_sim_clean$linelist + + # calculate quarterly cases by date of infection + x <- as_yearquarter(linelist$date_of_infection) + (dat <- aggregate(list(cases = x), by = list(quarter = x), FUN = length)) + + # by default labels are centred + (quarter_plot <- + ggplot2::ggplot(dat, ggplot2::aes(quarter, cases)) + + ggplot2::geom_col(width = 1, colour = "white") + + ggplot2::theme_bw() + + ggplot2::theme( + axis.text.x = ggplot2::element_text( + angle = 45, + hjust = 1 + ) + ) + + ggplot2::xlab("")) + + # To obtain centred labels you must explicitly set a date format + # in the scale: + quarter_plot + scale_x_grates_yearquarter(format = "%Y-%m-%d") + ## Don't show: + }) # examplesIf > linelist <- outbreaks::ebola_sim_clean$linelist > x <- as_yearquarter(linelist$date_of_infection) > (dat <- aggregate(list(cases = x), by = list(quarter = x), FUN = length)) quarter cases 1 2014-Q1 1 2 2014-Q2 143 3 2014-Q3 1449 4 2014-Q4 1474 5 2015-Q1 602 6 2015-Q2 73 > (quarter_plot <- ggplot2::ggplot(dat, ggplot2::aes(quarter, cases)) + + ggplot2::geom_col(width = 1, colour = "white") + ggplot2::theme_bw() + ggplot2::theme(axis.text.x = ggplot2::element_text(angle = 45, + hjust = 1)) + ggplot2::xlab("")) > quarter_plot + scale_x_grates_yearquarter(format = "%Y-%m-%d") > ## End(Don't show) > > > > cleanEx() > nameEx("scale_x_grates_yearweek") > ### * scale_x_grates_yearweek > > flush(stderr()); flush(stdout()) > > ### Name: scale_x_grates_yearweek > ### Title: Yearweek scale > ### Aliases: scale_x_grates_yearweek scale_x_grates_yearweek_monday > ### scale_x_grates_yearweek_isoweek scale_x_grates_yearweek_tuesday > ### scale_x_grates_yearweek_wednesday scale_x_grates_yearweek_thursday > ### scale_x_grates_yearweek_friday scale_x_grates_yearweek_saturday > ### scale_x_grates_yearweek_sunday scale_x_grates_yearweek_epiweek > > ### ** Examples > > ## Don't show: > if (requireNamespace("outbreaks") && requireNamespace("ggplot2")) withAutoprint({ # examplesIf + ## End(Don't show) + + # use simulated linelist data from the outbreaks package + linelist <- outbreaks::ebola_sim_clean$linelist + x <- as_yearweek(linelist$date_of_infection, firstday = 4) + dat <- aggregate(list(cases = x), by = list(week = x), FUN = length) + + # plot the output + (week_plot <- + ggplot2::ggplot(dat, ggplot2::aes(week, cases)) + + ggplot2::geom_col(width = 1, colour = "white") + + ggplot2::theme_bw()) + + # We can have non-centred date labels on the x_axis by using the + # associated scale function and explicitly specifying a format for the + # date labels and a value for firstday: + week_plot + scale_x_grates_yearweek(format = "%Y-%m-%d", firstday = 4) + ## Don't show: + }) # examplesIf > linelist <- outbreaks::ebola_sim_clean$linelist > x <- as_yearweek(linelist$date_of_infection, firstday = 4) > dat <- aggregate(list(cases = x), by = list(week = x), FUN = length) > (week_plot <- ggplot2::ggplot(dat, ggplot2::aes(week, cases)) + ggplot2::geom_col(width = 1, + colour = "white") + ggplot2::theme_bw()) > week_plot + scale_x_grates_yearweek(format = "%Y-%m-%d", firstday = 4) > ## End(Don't show) > > > > cleanEx() > nameEx("year_class") > ### * year_class > > flush(stderr()); flush(stdout()) > > ### Name: year_class > ### Title: Year class > ### Aliases: year_class year as_year as_year.default as_year.Date > ### as_year.POSIXt as_year.character as_year.factor is_year > > ### ** Examples > > > # date coercion > as_year(Sys.Date()) [1] 2026 > > # POSIXt coercion > as_year(as.POSIXct("2019-03-04 01:01:01", tz = "America/New_York")) [1] 2019 > > # Character coercion > as_year("2019-05-03") [1] 2019 > > # direct construction > year(2011:2020) [1] 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 > > > > > cleanEx() > nameEx("yearmonth_class") > ### * yearmonth_class > > flush(stderr()); flush(stdout()) > > ### Name: yearmonth_class > ### Title: Yearmonth class > ### Aliases: yearmonth_class yearmonth as_yearmonth as_yearmonth.default > ### as_yearmonth.Date as_yearmonth.POSIXt as_yearmonth.character > ### as_yearmonth.factor new_yearmonth is_yearmonth > > ### ** Examples > > > # date coercion > as_yearmonth(Sys.Date()) [1] "2026-Nov" > > # POSIXt coercion > as_yearmonth(as.POSIXct("2019-03-04 01:01:01", tz = "America/New_York")) [1] "2019-Mar" > > # character coercion > as_yearmonth("2019-05-03") [1] "2019-May" > > # construction > yearmonth(year = 2000, month = 3) [1] "2000-Mar" > > # direct construction > d <- seq.Date(from = as.Date("1970-01-01"), by = "month", length.out = 10) > stopifnot( + identical( + as_yearmonth(d), + new_yearmonth(0:9) + ) + ) > > > > > cleanEx() > nameEx("yearquarter_class") > ### * yearquarter_class > > flush(stderr()); flush(stdout()) > > ### Name: yearquarter_class > ### Title: Yearquarter class > ### Aliases: yearquarter_class yearquarter as_yearquarter > ### as_yearquarter.default as_yearquarter.Date as_yearquarter.POSIXt > ### as_yearquarter.character as_yearquarter.factor new_yearquarter > ### is_yearquarter > > ### ** Examples > > > # date coercion > as_yearquarter(Sys.Date()) [1] "2026-Q4" > > # POSIXt coercion > as_yearquarter(as.POSIXct("2019-03-04 01:01:01", tz = "America/New_York")) [1] "2019-Q1" > > # character coercion > as_yearquarter("2019-05-03") [1] "2019-Q2" > > # construction > yearquarter(year = 2000, quarter = 3) [1] "2000-Q3" > > # direct construction > d <- seq.Date(from = as.Date("1970-01-01"), by = "quarter", length.out = 4) > stopifnot( + identical( + as_yearquarter(d), + new_yearquarter(0:3) + ) + ) > > > > > > cleanEx() > nameEx("yearweek_class") > ### * yearweek_class > > flush(stderr()); flush(stdout()) > > ### Name: yearweek_class > ### Title: Yearweek class > ### Aliases: yearweek_class yearweek as_yearweek as_yearweek.default > ### as_yearweek.Date as_yearweek.POSIXt as_yearweek.character > ### as_yearweek.factor new_yearweek is_yearweek > > ### ** Examples > > > # date coercion > as_yearweek(Sys.Date()) [1] "2026-W46" > > # POSIXt coercion > as_yearweek(as.POSIXct("2019-03-04 01:01:01", tz = "America/New_York")) [1] "2019-W10" > > # character coercion with Friday as the first day of the week > as_yearweek("2019-05-03", firstday = 5) # first day is Friday [1] "2019-W18" > > # character coercion in yearweek format > as_yearweek("2019-W12", format = "yearweek") [1] "2019-W12" > > # construction > yearweek(year = 2000, week = 3) [1] "2000-W03" > > # direct construction > stopifnot( + identical( + new_yearweek(0:1, firstday = 1), + as_yearweek("1969-12-29", firstday = 1) + 0:1 + ) + ) > > > > > ### *