Skip to content

Commit

Permalink
added f_month
Browse files Browse the repository at this point in the history
  • Loading branch information
trinker committed Dec 20, 2016
1 parent 05a3070 commit 904f073
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 3 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Description: Format numbers for publication; includes the removal of
p-value formatter.
Depends: R (>= 3.2.0)
Suggests: testthat
Date: 2016-10-12
Date: 2016-12-19
License: GPL-2
LazyData: TRUE
Roxygen: list(wrap = FALSE)
Expand Down
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ export(f_bills)
export(f_comma)
export(f_dollar)
export(f_mills)
export(f_month)
export(f_num)
export(f_number2month)
export(f_ordinal)
export(f_percent)
export(f_prefix)
Expand Down
3 changes: 1 addition & 2 deletions R/f_affix.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@
#' @param x A vector of elements to append with an affix.
#' @param prefix A string to append to the front of elements.
#' @param suffix A string to append to the back of elements.
#' @return
#' @return Returns a string of affix appended digits.
#' @export
#' @rdname f_affix
#' @seealso
#' @examples
#' f_affix(1:5, "-", "%")
#' f_affix(f_num(1:5, 2), "-", "%")
Expand Down
25 changes: 25 additions & 0 deletions R/f_month.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#' Format Months to One Letter Abbreviation
#'
#' Format long month name or integer formats to a single capital letter. Useful
#' for plot scales as a way to save space. \code{f_month} is used for
#' nominal data where as \code{f_number2month} is reserved for integers
#' 1-12.
#'
#' @param x A vector of month names or integers 1-12.
#' @return Returns a single letter month abbreviation atomic vector.
#' @export
#' @rdname f_month
#' @examples
#' f_month(month.name)
#' f_number2month(1:12)
f_month <- function(x) {
toupper(gsub("(^.)(.+)", "\\1", as.character(x)))
}


#' @export
#' @rdname f_month
f_number2month <- function(x) {
toupper(gsub("(^.)(.+)", "\\1", month.abb[x]))
}

3 changes: 3 additions & 0 deletions man/f_affix.Rd

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

28 changes: 28 additions & 0 deletions man/f_month.Rd

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

0 comments on commit 904f073

Please sign in to comment.