Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend examples and see also of sprintf_format function #269

Closed
wants to merge 13 commits into from
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions R/format_value.R
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,36 @@ check_aligns <- function(algn) {
#' string \code{format}.
#' @seealso \code{\link[base]{sprintf}}
#'
#' \code{\link[formatters]{round_fmt}}
#'
#' \code{\link[formatters]{list_formats}}
#'
martincadek marked this conversation as resolved.
Show resolved Hide resolved
#' @examples
#' fmtfun <- sprintf_format("(N=%i")
#' format_value(100, format = fmtfun)
#'
#' fmtfun2 <- sprintf_format("%.4f - %.2f")
#' format_value(list(12.23456, 2.724))
#'
#' # You can also customise rtables values
#' fmtfun3 <- sprintf_format("this range => %.1f")
#' format_value(100, format = fmtfun3)
#'
#' fmtfun4 <- sprintf_format("sadbasd asa a %.2f asda a %.1f")
martincadek marked this conversation as resolved.
Show resolved Hide resolved
#' format_value(list(12.23456, 2.724), format = fmtfun4)
#' \dontrun{
#' require(rtable)
#' lyt <- basic_table() %>%
#' split_cols_by("Species") %>%
#' analyze("Sepal.Length", afun = function(x) {
#' list(
#' "mean (sd)" = rcell(c(mean(x), sd(x)), format = fmtfun4),
#' "range" = rcell(diff(range(x)), format = fmtfun3)
#' )
#' })
martincadek marked this conversation as resolved.
Show resolved Hide resolved
#' build_table(lyt, iris)
#' }
#'
sprintf_format <- function(format) {
function(x, ...) {
do.call(sprintf, c(list(fmt = format), x))
Expand Down
24 changes: 24 additions & 0 deletions man/sprintf_format.Rd

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

Loading