@@ -219,7 +219,7 @@ print_actions_steps <- function(x){
219219# ' date-based attributes.
220220# ' @keywords internal
221221
222- augment_calendar_tbl <- function (.data ,.date ){
222+ augment_standard_calendar_tbl <- function (.data ,.date ){
223223
224224lubridate :: days
225225 # create attibutes
@@ -311,7 +311,7 @@ lubridate::days
311311# ' @return A dbi containing the original data along with all generated
312312# ' date-based attributes.
313313# ' @keywords internal
314- augment_calendar_dbi <- function (.data ,.date ){
314+ augment_standard_calendar_dbi <- function (.data ,.date ){
315315
316316
317317 date_vec <- rlang :: as_label(.date )
@@ -357,11 +357,8 @@ augment_calendar_dbi <- function(.data,.date){
357357
358358
359359
360-
361-
362-
363360# ' @title Add Comprehensive Date-Based Attributes to a DBI lazy frame or tibble object
364- # ' @name augment_calendar
361+ # ' @name augment_standard_calendar
365362# ' @description
366363# ' This function takes a data frame and a date column and generates a wide set of
367364# ' derived date attributes. These include start/end dates for year, quarter,
@@ -407,7 +404,7 @@ augment_calendar_dbi <- function(.data,.date){
407404# ' @return A dbi or tibble containing the original data along with all generated
408405# ' date-based attributes.
409406# '
410- augment_calendar <- function (.data ,.date ){
407+ augment_standard_calendar <- function (.data ,.date ){
411408
412409 data_class <- class(.data )
413410
@@ -420,7 +417,7 @@ augment_calendar <- function(.data,.date){
420417
421418 if (any(data_class %in% " tbl_lazy" )){
422419
423- out <- augment_calendar_dbi (.data = .data ,.date = .date_var )
420+ out <- augment_standard_calendar_dbi (.data = .data ,.date = .date_var )
424421
425422 return (out )
426423
@@ -429,7 +426,7 @@ augment_calendar <- function(.data,.date){
429426
430427 if (any(data_class %in% " tbl" )){
431428
432- out <- augment_calendar_tbl (.data = .data ,.date = !! .date_var )
429+ out <- augment_standard_calendar_tbl (.data = .data ,.date = !! .date_var )
433430
434431 return (out )
435432 }
@@ -460,6 +457,121 @@ closest_sunday_feb1 <- function(year) {
460457}
461458
462459
460+ # ' Create Non-Standard Month
461+ # '
462+ # ' @param .data non-standard calendar table
463+ # ' @param pattern '554','545' or '445'
464+ # '
465+ # ' @returns DBI object
466+ # '
467+ # ' @keywords internal
468+ create_ns_month <- function (.data ,pattern ){
469+
470+
471+ valid_colnames <- c(" week_ns" ," year_ns" )
472+ valid_pattern <- c(" 544" ," 545" ," 445" )
473+
474+
475+ assertthat :: assert_that(
476+ pattern %in% valid_pattern
477+ ,msg = cli :: cli_abort(" Please select {.or {.val {valid_pattern}}}" )
478+ )
479+
480+
481+ assertthat :: assert_that(
482+ pattern %in% valid_pattern
483+ ,msg = cli :: cli_abort(" Please ensure [.val week_ns] and [.val year_ns] are in the dataset" )
484+ )
485+
486+
487+ if (pattern == " 544" ){
488+
489+ valid_cumulative_months <- cumsum(rep(c(5 ,4 ,4 ),4 ))
490+
491+ out <-
492+ .data | >
493+ dplyr :: mutate(
494+ .by = year_ns
495+ ,month_ns = dplyr :: case_when(
496+ # either framing it in advance or somehow passing a arg to it
497+ week_ns < = !! valid_cumulative_months [[1 ]]~ 1
498+ ,week_ns < = !! valid_cumulative_months [[2 ]]~ 2
499+ ,week_ns < = !! valid_cumulative_months [[3 ]]~ 3
500+ ,week_ns < = !! valid_cumulative_months [[4 ]]~ 4
501+ ,week_ns < = !! valid_cumulative_months [[5 ]]~ 5
502+ ,week_ns < = !! valid_cumulative_months [[6 ]]~ 6
503+ ,week_ns < = !! valid_cumulative_months [[7 ]]~ 7
504+ ,week_ns < = !! valid_cumulative_months [[8 ]]~ 8
505+ ,week_ns < = !! valid_cumulative_months [[9 ]]~ 9
506+ ,week_ns < = !! valid_cumulative_months [[10 ]]~ 10
507+ ,week_ns < = !! valid_cumulative_months [[11 ]]~ 11
508+ ,week_ns < = !! valid_cumulative_months [[12 ]]~ 12
509+ ,.default = 13
510+ )
511+ )
512+ }
513+
514+ if (pattern == " 445" ){
515+
516+ valid_cumulative_months <- cumsum(rep(c(4 ,4 ,5 ),4 ))
517+
518+ out <- .data | >
519+ dplyr :: mutate(
520+ .by = year_ns
521+ ,month_ns = dplyr :: case_when(
522+ # either framing it in advance or somehow passing a arg to it
523+ week_ns < = !! valid_cumulative_months [[1 ]]~ 1
524+ ,week_ns < = !! valid_cumulative_months [[2 ]]~ 2
525+ ,week_ns < = !! valid_cumulative_months [[3 ]]~ 3
526+ ,week_ns < = !! valid_cumulative_months [[4 ]]~ 4
527+ ,week_ns < = !! valid_cumulative_months [[5 ]]~ 5
528+ ,week_ns < = !! valid_cumulative_months [[6 ]]~ 6
529+ ,week_ns < = !! valid_cumulative_months [[7 ]]~ 7
530+ ,week_ns < = !! valid_cumulative_months [[8 ]]~ 8
531+ ,week_ns < = !! valid_cumulative_months [[9 ]]~ 9
532+ ,week_ns < = !! valid_cumulative_months [[10 ]]~ 10
533+ ,week_ns < = !! valid_cumulative_months [[11 ]]~ 11
534+ ,week_ns < = !! valid_cumulative_months [[12 ]]~ 12
535+ ,.default = 13
536+ )
537+ )
538+ }
539+
540+
541+ if (pattern == " 454" ){
542+
543+ valid_cumulative_months <- cumsum(rep(c(4 ,5 ,4 ),4 ))
544+
545+ out <- .data | >
546+ dplyr :: mutate(
547+ .by = year_ns
548+ ,month_ns = dplyr :: case_when(
549+ # either framing it in advance or somehow passing a arg to it
550+ week_ns < = !! valid_cumulative_months [[1 ]]~ 1
551+ ,week_ns < = !! valid_cumulative_months [[2 ]]~ 2
552+ ,week_ns < = !! valid_cumulative_months [[3 ]]~ 3
553+ ,week_ns < = !! valid_cumulative_months [[4 ]]~ 4
554+ ,week_ns < = !! valid_cumulative_months [[5 ]]~ 5
555+ ,week_ns < = !! valid_cumulative_months [[6 ]]~ 6
556+ ,week_ns < = !! valid_cumulative_months [[7 ]]~ 7
557+ ,week_ns < = !! valid_cumulative_months [[8 ]]~ 8
558+ ,week_ns < = !! valid_cumulative_months [[9 ]]~ 9
559+ ,week_ns < = !! valid_cumulative_months [[10 ]]~ 10
560+ ,week_ns < = !! valid_cumulative_months [[11 ]]~ 11
561+ ,week_ns < = !! valid_cumulative_months [[12 ]]~ 12
562+ ,.default = 13
563+ )
564+ )
565+ }
566+
567+ return (out )
568+
569+
570+ }
571+
572+
573+
574+
463575utils :: globalVariables(
464576 c(
465577 " desc" ,
0 commit comments