Skip to content

Commit

Permalink
* constant_weekdays_abbreviation added to provide an abbreviated fo…
Browse files Browse the repository at this point in the history
…rm of

  weekdays.

* `f_month_name` & `f_month_abbreviation` added to convert to full name and
  3 letter abbreviated month formats.

* `f_weekday_name` & `f_weekday_abbreviation` added to convert to full name and
  3 letter abbreviated weekday formats.
  • Loading branch information
Tyler Rinker committed Oct 23, 2018
1 parent 0071c12 commit 43aa7a9
Show file tree
Hide file tree
Showing 26 changed files with 812 additions and 35 deletions.
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,6 @@ env:
global:
- DISPLAY=:99.0
- BOOTSTRAP_LATEX=1

- NOT_CRAN=true
- secure: "nhzZdgVEOmRO/pCpkb6vBgTbLU2igXmb5gbX+QWaV5YzDT5pqMnT+AtE5/+GMH7QxfFE1SKeA/r2w8XomNMpDvhIIpedwHpGywRGK3rtav2u108oQ73m2k2D3AQZ/YTAx7xPgVwCMveUqZ3xDyGkt220J3Hwfkpe341B2xQH0JQ="

29 changes: 29 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,16 @@ S3method(f_month,POSIXt)
S3method(f_month,default)
S3method(f_month,hms)
S3method(f_month,numeric)
S3method(f_month_abbreviation,Date)
S3method(f_month_abbreviation,POSIXt)
S3method(f_month_abbreviation,default)
S3method(f_month_abbreviation,hms)
S3method(f_month_abbreviation,numeric)
S3method(f_month_name,Date)
S3method(f_month_name,POSIXt)
S3method(f_month_name,default)
S3method(f_month_name,hms)
S3method(f_month_name,numeric)
S3method(f_quarter,Date)
S3method(f_quarter,POSIXt)
S3method(f_quarter,default)
Expand All @@ -19,6 +29,16 @@ S3method(f_weekday,POSIXt)
S3method(f_weekday,default)
S3method(f_weekday,hms)
S3method(f_weekday,numeric)
S3method(f_weekday_abbreviation,Date)
S3method(f_weekday_abbreviation,POSIXt)
S3method(f_weekday_abbreviation,default)
S3method(f_weekday_abbreviation,hms)
S3method(f_weekday_abbreviation,numeric)
S3method(f_weekday_name,Date)
S3method(f_weekday_name,POSIXt)
S3method(f_weekday_name,default)
S3method(f_weekday_name,hms)
S3method(f_weekday_name,numeric)
S3method(f_year,Date)
S3method(f_year,POSIXt)
S3method(f_year,hms)
Expand All @@ -30,6 +50,7 @@ export(constant_months)
export(constant_months_abbreviation)
export(constant_quarters)
export(constant_weekdays)
export(constant_weekdays_abbreviation)
export(f_12_hour)
export(f_abbreviation)
export(f_affirm)
Expand Down Expand Up @@ -58,6 +79,8 @@ export(f_longitude)
export(f_mean_sd)
export(f_mills)
export(f_month)
export(f_month_abbreviation)
export(f_month_name)
export(f_num)
export(f_num_percent)
export(f_ordinal)
Expand All @@ -77,6 +100,8 @@ export(f_suffix)
export(f_thous)
export(f_title)
export(f_weekday)
export(f_weekday_abbreviation)
export(f_weekday_name)
export(f_wrap)
export(f_year)
export(ff_12_hour)
Expand Down Expand Up @@ -106,6 +131,8 @@ export(ff_longitude)
export(ff_mean_sd)
export(ff_mills)
export(ff_month)
export(ff_month_abbreviation)
export(ff_month_name)
export(ff_num)
export(ff_num_percent)
export(ff_ordinal)
Expand All @@ -125,6 +152,8 @@ export(ff_suffix)
export(ff_thous)
export(ff_title)
export(ff_weekday)
export(ff_weekday_abbreviation)
export(ff_weekday_name)
export(ff_wrap)
export(ff_year)
export(ffv_num_percent)
Expand Down
8 changes: 8 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,14 @@ MINOR FEATURES
* `f_pp` added to lower typing on a commonly used function and to also change
the default digits value to 0 as is typically used in plotting.

* `constant_weekdays_abbreviation` added to provide an abbreviated form of
weekdays.

* `f_month_name` & `f_month_abbreviation` added to convert to full name and
3 letter abbreviated month formats.

* `f_weekday_name` & `f_weekday_abbreviation` added to convert to full name and
3 letter abbreviated weekday formats.

IMPROVEMENTS

Expand Down
8 changes: 8 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,14 @@ numform 0.4.1 -
* `f_pp` added to lower typing on a commonly used function and to also change
the default digits value to 0 as is typically used in plotting.

* `constant_weekdays_abbreviation` added to provide an abbreviated form of
weekdays.

* `f_month_name` & `f_month_abbreviation` added to convert to full name and
3 letter abbreviated month formats.

* `f_weekday_name` & `f_weekday_abbreviation` added to convert to full name and
3 letter abbreviated weekday formats.

**IMPROVEMENTS**

Expand Down
10 changes: 10 additions & 0 deletions R/constants.R
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,16 @@ constant_months_abbreviation <- month.abb
constant_weekdays <- c("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday")


#'
#' \code{constant_weekdays_abbreviatio} - A constant for ordered weekday abbreviations.
#'
#' @keywords datasets
#' @name constant_weekdays_abbreviatio
#' @rdname constants
#' @export
constant_weekdays_abbreviation <- c("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat")


#' Constants
#'
#' \code{constant_quarters} - A constant for ordered quarters.
Expand Down
160 changes: 160 additions & 0 deletions R/f_month.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,26 @@
#' if (!require("pacman")) install.packages("pacman")
#' pacman::p_load(tidyverse)
#'
#' set.seed(11)
#' data_frame(
#' date = sample(seq(as.Date("1990/1/1"), by = "day", length.out = 2e4), 12)
#' ) %>%
#' mutate(
#' year_4 = f_year(date, 2),
#' year_2 = f_year(date, 4),
#' quarter = f_quarter(date),
#' month_name = f_month_name(date) %>%
#' as_factor(),
#' month_abbreviation = f_month_abbreviation(date) %>%
#' as_factor(),
#' month_short = f_month(date),
#' weekday_name = f_weekday_name(date),
#' weekday_abbreviation = f_weekday_abbreviation(date),
#' weekday_short = f_weekday(date),
#' weekday_short_distinct = f_weekday(date, distinct = TRUE)
#' )
#'
#'
#' set.seed(10)
#' dat <- data_frame(
#' month = sample(month.name, 1000, TRUE),
Expand Down Expand Up @@ -91,3 +111,143 @@ f_month.hms <- function(x, ...) {
ff_month <- function(...) {
function(x) {f_month(x)}
}












#' @export
#' @rdname f_month
f_month_name <- function(x, ...) {
UseMethod('f_month_name')
}



#' @export
#' @rdname f_month
#' @method f_month_name default
f_month_name.default <- function(x, ...) {
gsub("(^.)(.+)", "\\U\\1\\L\\2", as.character(x), perl = TRUE)
}

#' @export
#' @rdname f_month
#' @method f_month_name numeric
f_month_name.numeric <- function(x, ...) {
month.name[x]
}


#' @export
#' @rdname f_month
#' @method f_month_name Date
f_month_name.Date <- function(x, ...) {
format(x, "%B")
}


#' @export
#' @rdname f_month
#' @method f_month_name POSIXt
f_month_name.POSIXt <- function(x, ...) {
format(x, "%B")
}



#' @export
#' @rdname f_month
#' @method f_month_name hms
f_month_name.hms <- function(x, ...) {
f_month_name.POSIXt(as.POSIXct(x))
}



#' @export
#' @rdname f_month
ff_month_name <- function(...) {
function(x) {f_month_name(x)}
}








#' @export
#' @rdname f_month
f_month_abbreviation <- function(x, ...) {
UseMethod('f_month_abbreviation')
}



#' @export
#' @rdname f_month
#' @method f_month_abbreviation default
f_month_abbreviation.default <- function(x, ...) {
gsub("(^.)(.{2})()", "\\U\\1\\L\\2", as.character(x), perl = TRUE)
}

#' @export
#' @rdname f_month
#' @method f_month_abbreviation numeric
f_month_abbreviation.numeric <- function(x, ...) {
month.abb[x]
}


#' @export
#' @rdname f_month
#' @method f_month_abbreviation Date
f_month_abbreviation.Date <- function(x, ...) {
format(x, "%b")
}


#' @export
#' @rdname f_month
#' @method f_month_abbreviation POSIXt
f_month_abbreviation.POSIXt <- function(x, ...) {
format(x, "%b")
}



#' @export
#' @rdname f_month
#' @method f_month_abbreviation hms
f_month_abbreviation.hms <- function(x, ...) {
f_month_abbreviation.POSIXt(as.POSIXct(x))
}



#' @export
#' @rdname f_month
ff_month_abbreviation <- function(...) {
function(x) {f_month_abbreviation(x)}
}












Loading

0 comments on commit 43aa7a9

Please sign in to comment.