-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
*
f_date
and f_12_hour
added to convert dates and times into comm…
…on in-text form. close #8
- Loading branch information
Showing
9 changed files
with
196 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#' Format 12 Hour Times | ||
#' | ||
#' Format times to the typical 12 hour '%I:%M %p' in-text format. | ||
#' | ||
#' @param x A vector of coercable times. | ||
#' @param format A character string specifying the time output format. | ||
#' @param pad.char A character to use for leading padding if lengths of output | ||
#' are unequal. | ||
#' @param \ldots Other arguments passed to \code{\link[base]{as.POSIXct}}. | ||
#' @return Returns a string of publication ready 12 hour time stamps. | ||
#' @export | ||
#' @rdname f_12_hour | ||
#' @examples | ||
#' f_12_hour(Sys.time()) | ||
#' f_12_hour(Sys.time(), pad.char ='0') | ||
#' f_12_hour(Sys.time(), pad.char =' ') | ||
#' f_12_hour(Sys.time(), '%I:%M:%S %p') | ||
#' set.seed(10) | ||
#' times <- as.POSIXct(sample(seq_len(1e4), 12), origin = '1970-01-01') | ||
#' paste(f_12_hour(range(times)), collapse = ' to ') | ||
f_12_hour <- function(x, format = '%I:%M %p', pad.char = '', ...){ | ||
|
||
out <- format(as.POSIXct(x, ...), format = format) | ||
gsub('^0', pad.char, out) | ||
|
||
} | ||
|
||
|
||
#' @export | ||
#' @include utils.R | ||
#' @rdname f_12_hour | ||
ff_12_hour <- functionize(f_12_hour) | ||
|
||
|
||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#' Format Dates | ||
#' | ||
#' Format dates to the typical '%B %d, %Y in-text format. | ||
#' | ||
#' @param x A vector of coercable dates. | ||
#' @param format A character string specifying the date output format. | ||
#' @param \ldots Other arguments passed to \code{\link[base]{as.Date}}. | ||
#' @return Returns a string of publication ready dates. | ||
#' @export | ||
#' @rdname f_date | ||
#' @examples | ||
#' f_date(Sys.Date()) | ||
#' f_date(Sys.time()) | ||
#' f_date(Sys.time(), '%b-%y') | ||
#' set.seed(10) | ||
#' dates <- as.Date(sample(1:10000, 12), origin = '1970-01-01') | ||
#' paste(f_date(range(dates)), collapse = ' to ') | ||
f_date <- function(x, format = '%B %d, %Y', ...){ | ||
|
||
format(as.Date(x, ...), format = format) | ||
|
||
} | ||
|
||
#' @export | ||
#' @include utils.R | ||
#' @rdname f_date | ||
ff_date <- functionize(f_date) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.