Skip to content

Commit

Permalink
gave f_12_hour the ability to handle integers
Browse files Browse the repository at this point in the history
  • Loading branch information
Tyler Rinker committed Aug 18, 2017
1 parent b3f40a7 commit 872690c
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 39 deletions.
41 changes: 9 additions & 32 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -3,41 +3,18 @@ Title: Tools to Format Numbers for Publication
Version: 0.1.1
Authors@R: c(person("Tyler", "Rinker", email = "tyler.rinker@gmail.com", role = c("aut", "cre")))
Maintainer: Tyler Rinker <tyler.rinker@gmail.com>
Description: Format numbers for publication; includes the removal of leading zeros, standardization of number
of digits, addition of affixes, and a p-value formatter. These tools combine the functionality of
several 'base' functions such as paste(), format(), and sprintf() into specific use case
functions that are named in a way that is consistent with usage, making their names easy to
remember and easy to deploy.
Description: Format numbers for publication; includes the removal of leading zeros, standardization of number of digits, addition
of affixes, and a p-value formatter. These tools combine the functionality of several 'base' functions such as
paste(), format(), and sprintf() into specific use case functions that are named in a way that is consistent with
usage, making their names easy to remember and easy to deploy.
Depends: R (>= 3.2.0)
Suggests: testthat
Date: 2017-08-11
Date: 2017-08-18
License: GPL-2
LazyData: TRUE
Roxygen: list(wrap = FALSE)
RoxygenNote: 6.0.1
Collate:
'alignment.R'
'as_factor.R'
'utils.R'
'f_12_hour.R'
'f_affirm.R'
'f_affix.R'
'f_comma.R'
'f_date.R'
'f_denom.R'
'f_dollar.R'
'f_logical.R'
'f_month.R'
'f_num.R'
'f_ordinal.R'
'f_pad_zero.R'
'f_parenthesis.R'
'f_percent.R'
'f_pval.R'
'f_sign.R'
'f_weekday.R'
'fv_num_percent.R'
'fv_percent.R'
'fv_percent_diff.R'
'fv_runs.R'
'numform-package.R'
Collate: 'alignment.R' 'as_factor.R' 'utils.R' 'f_12_hour.R' 'f_affirm.R' 'f_affix.R' 'f_comma.R' 'f_date.R' 'f_denom.R'
'f_dollar.R' 'f_logical.R' 'f_month.R' 'f_num.R' 'f_ordinal.R' 'f_pad_zero.R' 'f_parenthesis.R' 'f_percent.R'
'f_pval.R' 'f_sign.R' 'f_weekday.R' 'fv_num_percent.R' 'fv_percent.R' 'fv_percent_diff.R' 'fv_runs.R'
'numform-package.R'
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Generated by roxygen2: do not edit by hand

S3method(f_12_hour,default)
S3method(f_12_hour,integer)
S3method(f_month,Date)
S3method(f_month,POSIXlt)
S3method(f_month,default)
Expand Down
2 changes: 1 addition & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ numform 0.0.6 -
control in format (previously +/- were assigned). This enables the ability to
give other characters tailored for document formats such as html, LaTeX, etc.

IMPROVEMENTS
**IMPROVEMENTS**

**CHANGES**

Expand Down
25 changes: 24 additions & 1 deletion R/f_12_hour.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,40 @@
#' f_12_hour(Sys.time(), pad.char ='0')
#' f_12_hour(Sys.time(), pad.char =' ')
#' f_12_hour(Sys.time(), '%I:%M:%S %p')
#' f_12_hour(0:24, '%I %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 = '', ...){
f_12_hour <- function(x = Sys.time(), format = '%I:%M %p', pad.char = '', ...){
UseMethod('f_12_hour')
}


#' @export
#' @rdname f_12_hour
#' @method f_12_hour default
f_12_hour.default <- function(x, format = '%I:%M %p', pad.char = '', ...){

out <- format(as.POSIXct(x, ...), format = format)
gsub('^0', pad.char, out)

}


#' @export
#' @rdname f_12_hour
#' @method f_12_hour integer
f_12_hour.integer <- function(x, format = '%I:%M %p', pad.char = '', ...){


out <- format(as.POSIXct(paste0("2017-08-18 ", ifelse(nchar(x) == 1, '0', ''), x, ":00:00")), format=format)

gsub('^0', pad.char, out)

}



#' @export
#' @include utils.R
#' @rdname f_12_hour
Expand Down
9 changes: 8 additions & 1 deletion man/f_12_hour.Rd

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

2 changes: 1 addition & 1 deletion man/f_date.Rd

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

6 changes: 3 additions & 3 deletions man/f_weekday.Rd

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

0 comments on commit 872690c

Please sign in to comment.