From 76b10c92f4a57d6e0e9a1e983486ae0959084dc0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gergely=20Dar=C3=B3czi?= Date: Mon, 26 Aug 2013 19:10:30 +0200 Subject: [PATCH] new panderOption: big.mark --- R/options.R | 4 +++- R/pandoc.R | 11 ++++++----- man/panderOptions.Rd | 7 ++++--- man/pandoc.table.return.Rd | 3 +++ 4 files changed, 16 insertions(+), 9 deletions(-) diff --git a/R/options.R b/R/options.R index 2bf2f3b0..2695405c 100644 --- a/R/options.R +++ b/R/options.R @@ -4,6 +4,7 @@ options('pander' = list( 'digits' = 4, 'decimal.mark' = '.', + 'big.mark' = '', 'round' = Inf, 'keep.trailing.zeros' = FALSE, 'date' = '%Y/%m/%d %X', @@ -189,7 +190,8 @@ masked.plots$plot <- masked.plots$barplot <- masked.plots$lines <- masked.plots$ #' #' \itemize{ #' \item \code{digits}: numeric (default: \code{2}) passed to \code{format} -#' \item \code{decimal.mark}: numeric (default: \code{.}) passed to \code{format} +#' \item \code{decimal.mark}: string (default: \code{.}) passed to \code{format} +#' \item \code{big.mark}: string (default: '') passed to \code{format} #' \item \code{round}: numeric (default: \code{Inf}) passed to \code{round} #' \item \code{keep.trailing.zeros}: boolean (default: \code{FALSE}) to show or remove trailing zeros in numbers #' \item \code{date}: string (default: \code{'\%Y/\%m/\%d \%X'}) passed to \code{format} when printing dates (\code{POSIXct} or \code{POSIXt}) diff --git a/R/pandoc.R b/R/pandoc.R index a49b1978..44359d21 100644 --- a/R/pandoc.R +++ b/R/pandoc.R @@ -441,6 +441,7 @@ pandoc.list <- function(...) #' @param caption caption (string) to be shown under the table #' @param digits passed to \code{format} #' @param decimal.mark passed to \code{format} +#' @param big.mark passed to \code{format} #' @param round passed to \code{round} #' @param justify defines alignment in cells passed to \code{format}. Can be \code{left}, \code{right} or \code{centre}, which latter can be also spelled as \code{center}. Defaults to \code{centre}. #' @param style which Pandoc style to use: \code{simple}, \code{multiline}, \code{grid} or \code{rmarkdown} @@ -522,7 +523,7 @@ pandoc.list <- function(...) #' #' emphasize.strong.cells(which(t > 20, arr.ind = TRUE)) #' pandoc.table(t) -pandoc.table.return <- function(t, caption, digits = panderOptions('digits'), decimal.mark = panderOptions('decimal.mark'), round = panderOptions('round'), justify, style = c('multiline', 'grid', 'simple', 'rmarkdown'), split.tables = panderOptions('table.split.table'), split.cells = panderOptions('table.split.cells'), keep.trailing.zeros = panderOptions('keep.trailing.zeros'), emphasize.rows, emphasize.cols, emphasize.cells, emphasize.strong.rows, emphasize.strong.cols, emphasize.strong.cells, ...) { +pandoc.table.return <- function(t, caption, digits = panderOptions('digits'), decimal.mark = panderOptions('decimal.mark'), big.mark = panderOptions('big.mark'), round = panderOptions('round'), justify, style = c('multiline', 'grid', 'simple', 'rmarkdown'), split.tables = panderOptions('table.split.table'), split.cells = panderOptions('table.split.cells'), keep.trailing.zeros = panderOptions('keep.trailing.zeros'), emphasize.rows, emphasize.cols, emphasize.cells, emphasize.strong.rows, emphasize.strong.cols, emphasize.strong.cells, ...) { ## helper functions table.expand <- function(cells, cols.width, justify, sep.cols) { @@ -672,15 +673,15 @@ pandoc.table.return <- function(t, caption, digits = panderOptions('digits'), de t[t.n] <- round(t[t.n], round) if (!keep.trailing.zeros) { switch(as.character(length(dim(t))), - '0' = t[t.n] <- sapply(t[t.n], format, trim = TRUE, digits = digits, decimal.mark = decimal.mark), - '1' = t[t.n] <- apply(t[t.n, drop = FALSE], 1, format, trim = TRUE, digits = digits, decimal.mark = decimal.mark), - '2' = t[, t.n] <- apply(t[, t.n, drop = FALSE], c(1,2), format, trim = TRUE, digits = digits, decimal.mark = decimal.mark)) + '0' = t[t.n] <- sapply(t[t.n], format, trim = TRUE, digits = digits, decimal.mark = decimal.mark, big.mark = big.mark), + '1' = t[t.n] <- apply(t[t.n, drop = FALSE], 1, format, trim = TRUE, digits = digits, decimal.mark = decimal.mark, big.mark = big.mark), + '2' = t[, t.n] <- apply(t[, t.n, drop = FALSE], c(1,2), format, trim = TRUE, digits = digits, decimal.mark = decimal.mark, big.mark = big.mark)) } } ## drop unexpected classes and revert back to a common format if (keep.trailing.zeros) - t <- format(t, trim = TRUE, digits = digits, decimal.mark = decimal.mark) + t <- format(t, trim = TRUE, digits = digits, decimal.mark = decimal.mark, big.mark = big.mark) else t <- format(t, trim = TRUE) diff --git a/man/panderOptions.Rd b/man/panderOptions.Rd index 7c660f97..a55b2464 100644 --- a/man/panderOptions.Rd +++ b/man/panderOptions.Rd @@ -21,9 +21,10 @@ \itemize{ \item \code{digits}: numeric (default: \code{2}) passed to \code{format} \item - \code{decimal.mark}: numeric (default: \code{.}) passed - to \code{format} \item \code{round}: numeric (default: - \code{Inf}) passed to \code{round} \item + \code{decimal.mark}: string (default: \code{.}) passed to + \code{format} \item \code{big.mark}: string (default: '') + passed to \code{format} \item \code{round}: numeric + (default: \code{Inf}) passed to \code{round} \item \code{keep.trailing.zeros}: boolean (default: \code{FALSE}) to show or remove trailing zeros in numbers \item \code{date}: string (default: \code{'\%Y/\%m/\%d diff --git a/man/pandoc.table.return.Rd b/man/pandoc.table.return.Rd index 6c24497c..0d8bc282 100644 --- a/man/pandoc.table.return.Rd +++ b/man/pandoc.table.return.Rd @@ -6,6 +6,7 @@ pandoc.table.return(t, caption, digits = panderOptions("digits"), decimal.mark = panderOptions("decimal.mark"), + big.mark = panderOptions("big.mark"), round = panderOptions("round"), justify, style = c("multiline", "grid", "simple", "rmarkdown"), split.tables = panderOptions("table.split.table"), @@ -25,6 +26,8 @@ \item{decimal.mark}{passed to \code{format}} + \item{big.mark}{passed to \code{format}} + \item{round}{passed to \code{round}} \item{justify}{defines alignment in cells passed to