Skip to content

Commit

Permalink
new panderOption: big.mark
Browse files Browse the repository at this point in the history
  • Loading branch information
daroczig committed Aug 26, 2013
1 parent 71a09e1 commit 76b10c9
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 9 deletions.
4 changes: 3 additions & 1 deletion R/options.R
Expand Up @@ -4,6 +4,7 @@
options('pander' = list(
'digits' = 4,
'decimal.mark' = '.',
'big.mark' = '',
'round' = Inf,
'keep.trailing.zeros' = FALSE,
'date' = '%Y/%m/%d %X',
Expand Down Expand Up @@ -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})
Expand Down
11 changes: 6 additions & 5 deletions R/pandoc.R
Expand Up @@ -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}
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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)

Expand Down
7 changes: 4 additions & 3 deletions man/panderOptions.Rd
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions man/pandoc.table.return.Rd
Expand Up @@ -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"),
Expand All @@ -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
Expand Down

0 comments on commit 76b10c9

Please sign in to comment.