From: dscott Date: Wed, 28 Aug 2013 05:23:52 +0000 (+0000) Subject: Changed documentation to advise on bug #4770 X-Git-Url: https://git.donarmstrong.com/?p=xtable.git;a=commitdiff_plain;h=b5759b9865fae6b967b713e948390fe9ec8eb49a Changed documentation to advise on bug #4770 git-svn-id: svn://scm.r-forge.r-project.org/svnroot/xtable@42 edb9625f-4e0d-4859-8d74-9fd3b1da38cb --- diff --git a/pkg/NEWS b/pkg/NEWS index 12d00d9..5dd0e4c 100644 --- a/pkg/NEWS +++ b/pkg/NEWS @@ -1,5 +1,8 @@ 1.7-2 (NOT YET RELEASED) * Fixed HTML gsub bug (#2795) + * Dealt with format.args bug (#4770). No code changes, but the + documentation of print.xtable was changed to warn of the problem + and to give a workaround as an example 1.7-1 (2013-02-24) * Fixed logicals bug (Req #1911) @@ -15,10 +18,10 @@ to exclude the version and timestamp comment. (Req #2246) * Added "caption.width" argument. If not NULL then the caption is placed in a "parbox" of the specified width. (Req #2247) - * Remove the check on whether the "floating.environment" is - in a list of known floating environments. Users want to use - floating environments from multiple options LaTeX - packages (Req #2488, #2578) + * Remove the check on whether the "floating.environment" is in a + list of known floating environments. Users want to use floating + environments from multiple options LaTeX packages (Req #2488, + #2578) 1.7-0 (2012-02-10) * Added some vectorization code to improve performance. diff --git a/pkg/R/print.xtable.R b/pkg/R/print.xtable.R index 35d4c46..d057595 100644 --- a/pkg/R/print.xtable.R +++ b/pkg/R/print.xtable.R @@ -123,7 +123,7 @@ print.xtable <- function(x, ## Original code before changes in version 1.6-1 ## PHEADER <- "\\hline\n" - ## booktabs code from Matthieu Stigler , + ## booktabs code from Matthieu Stigler , ## 1 Feb 2012 if(!booktabs){ PHEADER <- "\\hline\n" @@ -144,9 +144,9 @@ print.xtable <- function(x, if (!is.null(hline.after)) { ## booktabs change - Matthieu Stigler: fill the hline arguments ## separately, 1 Feb 2012 - ## + ## ## Code before booktabs change was: - ## add.to.row$pos[[npos+1]] <- hline.after + ## add.to.row$pos[[npos+1]] <- hline.after if (!booktabs){ add.to.row$pos[[npos+1]] <- hline.after @@ -178,8 +178,8 @@ print.xtable <- function(x, if (!all(!is.na(match(type, c("latex","html"))))) { stop("\"type\" must be in {\"latex\", \"html\"}") } - ## Disabling the check on known floating environments as many users - ## want to use additional environments. + ## Disabling the check on known floating environments as many users + ## want to use additional environments. # if (!all(!is.na(match(floating.environment, # c("table","table*","sidewaystable", # "margintable"))))) { @@ -324,7 +324,7 @@ print.xtable <- function(x, ESIZE <- "}\n" } BLABEL <- "\\label{" - ELABEL <- "}\n" + ELABEL <- "}\n" ## Added caption width (jeff.laake@nooa.gov) if(!is.null(caption.width)){ BCAPTION <- paste("\\parbox{",caption.width,"}{",sep="") @@ -332,13 +332,13 @@ print.xtable <- function(x, } else { BCAPTION <- NULL ECAPTION <- NULL - } + } if (is.null(short.caption)){ BCAPTION <- paste(BCAPTION,"\\caption{",sep="") } else { BCAPTION <- paste(BCAPTION,"\\caption[", short.caption, "]{", sep="") - } - ECAPTION <- paste(ECAPTION,"} \n",sep="") + } + ECAPTION <- paste(ECAPTION,"} \n",sep="") BROW <- "" EROW <- " \\\\ \n" BTH <- "" @@ -459,10 +459,10 @@ print.xtable <- function(x, info$language + " " + info$major + "." + info$minor + " by xtable " + packageDescription('xtable')$Version + " package" + ECOMMENT - if (!is.null(timestamp)){ + if (!is.null(timestamp)){ result <- result + BCOMMENT + timestamp + ECOMMENT } - } + } ## Claudio Agostinelli dated 2006-07-28 only.contents if (!only.contents) { result <- result + BTABLE @@ -558,26 +558,26 @@ print.xtable <- function(x, format.args$decimal.mark <- options()$OutDec } if(!varying.digits){ - curFormatArgs <- c(list( - x = xcol, - format = ifelse( attr( x, "digits", - exact = TRUE )[i+1] < 0, "E", - attr( x, "display", exact = TRUE )[i+1] ), - digits = abs( attr( x, "digits", - exact = TRUE )[i+1] )), - format.args) + curFormatArgs <- + c(list( + x = xcol, + format = + ifelse(attr(x, "digits", exact = TRUE )[i+1] < 0, "E", + attr(x, "display", exact = TRUE )[i+1]), + digits = abs(attr(x, "digits", exact = TRUE )[i+1])), + format.args) cols[, i+pos] <- do.call("formatC", curFormatArgs) }else{ for( j in 1:nrow( cols ) ) { - curFormatArgs <- c(list( - x = xcol[j], - format = ifelse( attr( x, "digits", - exact = TRUE )[j, i+1] < 0, "E", - attr( x, "display", - exact = TRUE )[i+1] ), - digits = abs( attr( x, "digits", - exact = TRUE )[j, i+1] )), - format.args) + curFormatArgs <- + c(list( + x = xcol[j], + format = + ifelse(attr(x, "digits", exact = TRUE )[j, i+1] < 0, + "E", attr(x, "display", exact = TRUE )[i+1]), + digits = + abs(attr(x, "digits", exact = TRUE )[j, i+1])), + format.args) cols[j, i+pos] <- do.call("formatC", curFormatArgs) } } @@ -679,10 +679,10 @@ as.string <- function(x, file = "", append = FALSE) { switch(data.class(x), character = return(string(x, file, append)), numeric = return(string(as.character(x), file, append)), - stop("Cannot coerse argument to a string")) + stop("Cannot coerce argument to a string")) if (class(x) == "string") return(x) - stop("Cannot coerse argument to a string") + stop("Cannot coerce argument to a string") } is.string <- function(x) { diff --git a/pkg/man/print.xtable.Rd b/pkg/man/print.xtable.Rd index efb537f..33a5f5d 100644 --- a/pkg/man/print.xtable.Rd +++ b/pkg/man/print.xtable.Rd @@ -145,7 +145,9 @@ the character vector that is returned invisibly.} \item{format.args}{List of arguments for the \code{formatC} function. For example, standard German number separators can be specified as - \code{format.args=list(big.mark = "'", decimal.mark = ","))}. } + \code{format.args=list(big.mark = "'", decimal.mark = + ","))}. \code{digits} and \code{format} arguments should not be + included in this list. See details. } \item{rotate.rownames}{If \code{TRUE}, the row names are displayed vertically in LaTeX. } \item{rotate.colnames}{If \code{TRUE}, the column names are displayed @@ -191,7 +193,15 @@ From version 1.6-1 the default values for the arguments other than \code{x} are obtainined using \code{getOption()}. Hence the user can set the values once with \code{options()} rather than setting them in - every call to \code{print.xtable()}. + every call to \code{print.xtable()}. + + The argument \code{format.args} is used to supply arguments to the + \code{formatC} function, but will throw an error if values for + \code{digits} or \code{format} are included in the list of + arguments. The recommended approach is to specify \code{digits} supply + the argument \code{digits} to \code{xtable}, and to specify + \code{format} supply the argument \code{display} to \code{xtable}. See + the examples. } \author{ David Dahl \email{dahl@stat.tamu.edu} with contributions and @@ -208,4 +218,25 @@ \code{\link{formatC}} } +\examples{ +df <- data.frame(A = c(1.00123, 33.1, 6), + B = c(111111, 3333333, 3123.233)) +## The following code gives the error +## formal argument "digits" matched by multiple actual arguments +## print(xtable(df, display = c("s","e","e")), +## format.args = list(digits = 3, big.mark = " ", decimal.mark = ",")) +## specify digits as argument to xtable instead +print(xtable(df, display = c("s","f","f"), digits = 4), + format.args = list(big.mark = " ", decimal.mark = ",")) +## The following code gives the error +## formal argument "format" matched by multiple actual arguments +## print(xtable(df, digits = 4), +## format.args = list(format = c("s","e","e"), +## big.mark = " ", decimal.mark = ",")) +## specify format using display argument in xtable +print(xtable(df, display = c("s","e","e"), digits = 4), + format.args = list(big.mark = " ", decimal.mark = ",")) + +} + \keyword{print} diff --git a/pkg/man/toLatex.Rd b/pkg/man/toLatex.Rd index e0cc1cc..bdf6c59 100644 --- a/pkg/man/toLatex.Rd +++ b/pkg/man/toLatex.Rd @@ -1,17 +1,26 @@ \name{toLatex.xtable} \alias{toLatex.xtable} \title{Convert Table to Latex} -\description{Function creating a LaTeX representation of an object of class \code{xtable}.} +\description{ + Function creating a LaTeX representation of an object of class + \code{xtable}. +} \usage{ - \method{toLatex}{xtable}(object, ...)} +\method{toLatex}{xtable}(object, ...) +} \arguments{ \item{object}{An object of class \code{"xtable"}.} \item{...}{Other arguments to \code{print.xtable}.} } \details{ - This function creates a LaTeX representation of an object of class \code{"xtable"}. This is a method for the generic \code{"toLatex"} in the core R package \code{"utils"}. + This function creates a LaTeX representation of an object of class + \code{"xtable"}. This is a method for the generic \code{"toLatex"} in + the core R package \code{"utils"}. +} +\author{ + Charles Roosen \email{roosen@gmail.com} with contributions and + suggestions from many others (see source code). } -\author{Charles Roosen \email{roosen@gmail.com} with contributions and suggestions from many others (see source code).} \seealso{\code{\link{print.xtable}}} \keyword{toLatex}