-\name{print.xtable}
-\alias{print.xtable}
-\title{Print Export Tables}
-\description{Function returning and displaying or writing to disk the LaTeX or HTML code associated with the supplied object of class \code{xtable}.}
-\usage{
- \method{print}{xtable}(x, type="latex", file="", append=FALSE, floating=TRUE,
- floating.environment="table", table.placement = "ht", caption.placement="bottom",
- latex.environments=c("center"),tabular.environment = "tabular", size=NULL,
- hline.after=c(-1,0,nrow(x)), NA.string = "", include.rownames=TRUE,
- include.colnames=TRUE, only.contents=FALSE, add.to.row=NULL,
- sanitize.text.function=NULL, sanitize.rownames.function=sanitize.text.function,
- sanitize.colnames.function=sanitize.text.function, math.style.negative=FALSE,
- html.table.attributes="border=1",
- print.result=TRUE, ...)}
-\arguments{
- \item{x}{An object of class \code{"xtable"}.}
- \item{type}{Type of table to produce. Possible values for \code{type} are \code{"latex"} or \code{"html"}.
- Default value is \code{"latex"}.}
- \item{file}{Name of file where the resulting code should be saved. If \code{file=""}, output is displayed on screen. Note that
- the function also (invisibly) returns a character vector of the results (which can be helpful for post-processing).
- Default value is \code{""}.}
- \item{append}{If \code{TRUE} and \code{file!=""}, code will be appended to \code{file} instead of overwriting \code{file}.
- Default value is \code{FALSE}.}
- \item{floating}{If \code{TRUE} and \code{type="latex"}, the resulting table will be a floating table (using, for example, \code{\\begin\{table\}} and \code{\\end\{table\}}). See \code{floating.environment} below. Default value is \code{TRUE}.}
- \item{floating.environment}{If \code{floating=TRUE} and \code{type="latex"}, the resulting table uses the specified floating environment.
- Possible values are \code{"table"}, \code{"table*"}, or \code{"sidewaystable"} (defined in the LaTeX package 'rotating').
- Default value is \code{"table"}.}
- \item{table.placement}{If \code{floating=TRUE} and \code{type="latex"}, the floating table will have placement given by \code{table.placement} where \code{table.placement} must be \code{NULL} or contain only elements of \{"h","t","b","p","!","H"\}.
- Default value is \code{"ht"}.}
- \item{caption.placement}{The caption will be have placed at the bottom of the table if \code{caption.placement} is \code{"bottom"} and at the top of the table if it equals \code{"top"}.
- Default value is \code{"bottom"}.}
- \item{latex.environments}{If \code{floating=TRUE} and \code{type="latex"}, the specificed latex environments (provided as a character vector) will enclose the tabuluar environment.
- Default value is \code{"center"}.}
- \item{tabular.environment}{When \code{type="latex"}, the tabular environment that will be used. Defaults to \code{"tabular"}. When working with tables that extend more than one page, using \code{tabular.environment="longtable"} and the LaTeX package \code{"longtable"} (see Fairbairns, 2005) allows one to typeset them uniformly. Note that \code{"floating"} should be set to \code{"FALSE"} when using the \code{"longtable"} environment.}
- \item{size}{An arbitrary character vector intended to be used to set the font size in a LaTeX table. The supplied value (if not \code{NULL}) is inserted just before the tabular environment starts. Default value is \code{NULL}.}
- \item{hline.after}{When \code{type="latex"}, a vector of numbers between -1 and \code{"nrow(x)"}, inclusive, indicating the rows after which a horizontal line should appear. If \code{NULL} is used no lines are produced. Default value is \code{c(-1,0,nrow(x))} which means draw a line before and after the columns names and at the end of the table. Repeated values are allowed.}
- \item{NA.string}{String to be used for missing values in table entries. Default value is \code{""}.}
- \item{include.rownames}{logical. If \code{TRUE} the rows names is printed. Default value is \code{TRUE}.}
- \item{include.colnames}{logical. If \code{TRUE} the columns names is printed. Default value is \code{TRUE}.}
- \item{only.contents}{logical. If \code{TRUE} only the rows of the table is printed. Default value is \code{FALSE}.}
- \item{add.to.row}{a list of two components. The first component (which should be called 'pos') is a list contains the position of rows on which extra commands should be added at the end, The second component (which should be called 'command') is a character vector of the same length of the first component which contains the command that should be added at the end of the specified rows. Default value is \code{NULL}, i.e. do not add commands.}
- \item{sanitize.text.function}{All non-numeric enteries (except row and column names) are sanitised in an attempt to remove characters which have special meaning for the output format. If \code{sanitize.text.function} is not NULL (the default), it should be a function taking a character vector and returning one, and will be used for the sanitization instead of the default internal function.}
- \item{sanitize.rownames.function}{Like the \code{sanitize.text.function}, but applicable to row names. The default uses the \code{sanitize.text.function}.}
- \item{sanitize.colnames.function}{Like the \code{sanitize.text.function}, but applicable to column names. The default uses the \code{sanitize.text.function}.}
- \item{math.style.negative}{In a LaTeX table, if \code{TRUE}, then use $-$ for the negative sign (as was the behavior prior to version 1.5-3). Default value is \code{FALSE}.}
- \item{html.table.attributes}{In an HTML table, attributes associated with the \code{<TABLE>} tag. Default value is \code{border=1}.}
- \item{print.result}{If \code{TRUE}, the generated table is printed to standard output. Set this to \code{FALSE} if you will just be using the character vector that is returned invisibly.}
- \item{...}{Additional arguments. (Currently ignored.)}
-}
-\details{
- This function displays or writes to disk the code to produce a table associated with an object \code{x} of class \code{"xtable"}.
- The resulting code is either a LaTeX or HTML table, depending on the value of \code{type}. The function also (invisibly) returns a character vector
- of the results (which can be helpful for post-processing).
-
- Since version 1.4 the non default behavior of \code{hline.after} is changed. To obtain the same results as the previous versions add to the \code{hline.after} vector the vector \code{c(-1, 0, nrow(x))} where \code{nrow(x)} is the numbers of rows of the object.
-
- From version 1.4-3, all non-numeric columns are sanitized, and all LaTeX special characters are sanitised for LaTeX output. See Section 3 of the \code{xtableGallery} vignette for an example of customising the sanitization.
- From version 1.4-4, the sanitization also applies to column names. To remove any text sanitization, specify \code{sanitize.text.function=function(x){x}}.
-}
-\author{David Dahl \email{dahl@stat.tamu.edu} with contributions and suggestions from many others (see source code).}
-\references{
- Fairbairns, Robin (2005) \emph{Tables longer than a single page} The UK List of TeX Frequently Asked Questions on the Web. \url{http://www.tex.ac.uk/cgi-bin/texfaq2html?label=longtab}
-}
-\seealso{\code{\link{xtable}}, \code{\link{caption}}, \code{\link{label}},
- \code{\link{align}}, \code{\link{digits}}, \code{\link{display}}, \code{\link{formatC}}}
-
-\keyword{print}
+\name{print.xtable}\r
+\alias{print.xtable}\r
+\title{Print Export Tables}\r
+\description{\r
+ Function returning and displaying or writing to disk the LaTeX or HTML\r
+ code associated with the supplied object of class \code{xtable}.\r
+}\r
+\usage{\r
+\method{print}{xtable}(x,\r
+ type = getOption("xtable.type", "latex"),\r
+ file = getOption("xtable.file", ""),\r
+ append = getOption("xtable.append", FALSE),\r
+ floating = getOption("xtable.floating", TRUE),\r
+ floating.environment = getOption("xtable.floating.environment", "table"),\r
+ table.placement = getOption("xtable.table.placement", "ht"),\r
+ caption.placement = getOption("xtable.caption.placement", "bottom"),\r
+ caption.width = getOption("xtable.caption.width", NULL),\r
+ latex.environments = getOption("xtable.latex.environments", c("center")),\r
+ tabular.environment = getOption("xtable.tabular.environment", "tabular"),\r
+ size = getOption("xtable.size", NULL),\r
+ hline.after = getOption("xtable.hline.after", c(-1,0,nrow(x))),\r
+ NA.string = getOption("xtable.NA.string", ""),\r
+ include.rownames = getOption("xtable.include.rownames", TRUE),\r
+ include.colnames = getOption("xtable.include.colnames", TRUE),\r
+ only.contents = getOption("xtable.only.contents", FALSE),\r
+ add.to.row = getOption("xtable.add.to.row", NULL),\r
+ sanitize.text.function = getOption("xtable.sanitize.text.function", NULL),\r
+ sanitize.rownames.function = getOption("xtable.sanitize.rownames.function",\r
+ sanitize.text.function),\r
+ sanitize.colnames.function = getOption("xtable.sanitize.colnames.function",\r
+ sanitize.text.function),\r
+ math.style.negative = getOption("xtable.math.style.negative", FALSE),\r
+ math.style.exponents = getOption("xtable.math.style.exponents", FALSE),\r
+ html.table.attributes = getOption("xtable.html.table.attributes",\r
+ "border=1"),\r
+ print.results = getOption("xtable.print.results", TRUE),\r
+ format.args = getOption("xtable.format.args", NULL),\r
+ rotate.rownames = getOption("xtable.rotate.rownames", FALSE),\r
+ rotate.colnames = getOption("xtable.rotate.colnames", FALSE),\r
+ booktabs = getOption("xtable.booktabs", FALSE),\r
+ scalebox = getOption("xtable.scalebox", NULL),\r
+ width = getOption("xtable.width", NULL),\r
+ comment = getOption("xtable.comment", TRUE),\r
+ timestamp = getOption("xtable.timestamp", date()),\r
+ ...)}\r
+\arguments{\r
+ \item{x}{An object of class \code{"xtable"}.}\r
+ \item{type}{Type of table to produce. Possible values for \code{type}\r
+ are \code{"latex"} or \code{"html"}.\r
+ Default value is \code{"latex"}.}\r
+ \item{file}{Name of file where the resulting code should be saved. If\r
+ \code{file=""}, output is displayed on screen. Note that the\r
+ function also (invisibly) returns a character vector of the results\r
+ (which can be helpful for post-processing).\r
+ Default value is \code{""}.}\r
+ \item{append}{If \code{TRUE} and \code{file!=""}, code will be\r
+ appended to \code{file} instead of overwriting \code{file}.\r
+ Default value is \code{FALSE}.}\r
+ \item{floating}{If \code{TRUE} and \code{type="latex"}, the resulting\r
+ table will be a floating table (using, for example,\r
+ \code{\\begin\{table\}} and \code{\\end\{table\}}). See\r
+ \code{floating.environment} below.\r
+ Default value is \code{TRUE}. }\r
+ \item{floating.environment}{If \code{floating=TRUE} and\r
+ \code{type="latex"}, the resulting table uses the specified floating\r
+ environment. Possible values include \code{"table"}, \code{"table*"},\r
+ and other floating environments defined in LaTeX packages.\r
+ Default value is \code{"table"}.}\r
+ \item{table.placement}{If \code{floating=TRUE} and\r
+ \code{type="latex"}, the floating table will have placement given by\r
+ \code{table.placement} where \code{table.placement} must be\r
+ \code{NULL} or contain only elements of\r
+ \{"h","t","b","p","!","H"\}.\r
+ Default value is \code{"ht"}.}\r
+ \item{caption.placement}{The caption will be placed at the bottom\r
+ of the table if \code{caption.placement} is \code{"bottom"} and at\r
+ the top of the table if it equals \code{"top"}.\r
+ Default value is \code{"bottom"}.}\r
+ \item{caption.width}{The caption will be placed in a \code{"parbox"}\r
+ of the specified width if \code{caption.width} is not \code{NULL} and\r
+ \code{type="latex"}. Default value is \code{NULL}.}\r
+ \item{latex.environments}{If \code{floating=TRUE} and\r
+ \code{type="latex"}, the specified LaTeX environments (provided as\r
+ a character vector) will enclose the tabular environment.\r
+ Default value is \code{"center"}. }\r
+ \item{tabular.environment}{When \code{type="latex"}, the tabular\r
+ environment that will be used.\r
+ When working with tables that extend more than one page, using\r
+ \code{tabular.environment="longtable"} with the corresponding\r
+ LaTeX package (see Fairbairns, 2005) allows one to typeset them\r
+ uniformly. Note that \code{floating} should be set to\r
+ \code{FALSE} when using the \code{longtable} environment.\r
+ Default value is \code{"tabular"}.}\r
+ \item{size}{A character vector that is inserted just before the\r
+ tabular environment starts. This can be used to set the font size\r
+ and a variety of other table settings. Initial backslashes are\r
+ automatically prefixed, if not supplied by user.\r
+ Default value is \code{NULL}. }\r
+ \item{hline.after}{When \code{type="latex"}, a vector of numbers\r
+ between -1 and \code{nrow(x)}, inclusive, indicating the rows\r
+ after which a horizontal line should appear. If \code{NULL} is used\r
+ no lines are produced. Repeated values are allowed.\r
+ Default value is \code{c(-1,0,nrow(x))} which means draw a line\r
+ before and after the columns names and at the end of the\r
+ table.}\r
+ \item{NA.string}{String to be used for missing values in table\r
+ entries.\r
+ Default value is \code{""}.}\r
+ \item{include.rownames}{If \code{TRUE} the rows names are\r
+ printed.\r
+ Default value is \code{TRUE}.}\r
+ \item{include.colnames}{If \code{TRUE} the columns names are\r
+ printed.\r
+ Default value is \code{TRUE}.}\r
+ \item{only.contents}{If \code{TRUE} only the rows of the\r
+ table are printed.\r
+ Default value is \code{FALSE}. }\r
+ \item{add.to.row}{A list of two components. The first component (which\r
+ should be called 'pos') is a list that contains the position of rows on\r
+ which extra commands should be added at the end. The second\r
+ component (which should be called 'command') is a character vector\r
+ of the same length as the first component, which contains the command\r
+ that should be added at the end of the specified rows.\r
+ Default value is \code{NULL}, i.e. do not add commands.}\r
+ \item{sanitize.text.function}{All non-numeric entries (except row and\r
+ column names) are sanitized in an attempt to remove characters which\r
+ have special meaning for the output format. If\r
+ \code{sanitize.text.function} is not \code{NULL}, it should\r
+ be a function taking a character vector and returning one, and will\r
+ be used for the sanitization instead of the default internal\r
+ function.\r
+ Default value is \code{NULL}.}\r
+ \item{sanitize.rownames.function}{Like the\r
+ \code{sanitize.text.function}, but applicable to row names.\r
+ The default uses the \code{sanitize.text.function}. }\r
+ \item{sanitize.colnames.function}{Like the\r
+ \code{sanitize.text.function}, but applicable to column names.\r
+ The default uses the \code{sanitize.text.function}. }\r
+ \item{math.style.negative}{In a LaTeX table, if \code{TRUE}, then use\r
+ $-$ for the negative sign (as was the behavior prior to version 1.5-3).\r
+ Default value is \code{FALSE}.} \r
+ \item{math.style.exponents}{In a LaTeX table, if \code{TRUE} or\r
+ \code{"$$"}, then use \verb{$5 \times 10^{5}$} for 5e5. If\r
+ \code{"ensuremath"}, then use \verb{\\ensuremath{5 \times 10^{5}}}\r
+ for 5e5. If \code{"UTF-8"} or \code{"UTF-8"}, then use UTF-8 to\r
+ approximate the LaTeX typsetting for 5e5.\r
+ Default value is \code{FALSE}.}\r
+ \item{html.table.attributes}{In an HTML table, attributes associated\r
+ with the \code{<TABLE>} tag.\r
+ Default value is \code{"border=1"}.}\r
+ \item{print.results}{If \code{TRUE}, the generated table is printed to\r
+ standard output. Set this to \code{FALSE} if you will just be using\r
+ the character vector that is returned invisibly.\r
+ Default value is \code{TRUE}.}\r
+ \item{format.args}{List of arguments for the \code{formatC} function.\r
+ For example, standard German number separators can be specified as\r
+ \code{format.args=list(big.mark = "'", decimal.mark =\r
+ ","))}. The arguments \code{digits} and \code{format} should not be\r
+ included in this list. See details.\r
+ Default value is \code{NULL}.}\r
+ \item{rotate.rownames}{If \code{TRUE}, the row names are displayed\r
+ vertically in LaTeX.\r
+ Default value is \code{FALSE}.}\r
+ \item{rotate.colnames}{If \code{TRUE}, the column names are displayed\r
+ vertically in LaTeX.\r
+ Default value is \code{FALSE}.}\r
+ \item{booktabs}{If \code{TRUE}, the \code{toprule}, \code{midrule} and\r
+ \code{bottomrule} commands from the LaTeX "booktabs" package are used\r
+ rather than \code{hline} for the horizontal line tags. }\r
+ \item{scalebox}{If not \code{NULL}, a \code{scalebox} clause will be\r
+ added around the tabular environment with the specified value used\r
+ as the scaling factor.\r
+ Default value is \code{NULL}.}\r
+ \item{width}{If not \code{NULL}, the specified value is included in\r
+ parentheses between the tabular environment \code{begin} tag and the\r
+ alignment specification. This allows specification of the table\r
+ width when using tabular environments such as \code{tabular*} and\r
+ \code{tabularx}. Note that table width specification is not\r
+ supported with the \code{tabular} or \code{longtable} environments.\r
+ Default value is \code{NULL}.}\r
+ \item{comment}{If \code{TRUE}, the version and timestamp comment is\r
+ included. Default value is \code{TRUE}. }\r
+ \item{timestamp}{Timestamp to include in LaTeX comment. Set this\r
+ to \code{NULL} to exclude the timestamp. Default value is \code{date()}. }\r
+ \item{...}{Additional arguments. (Currently ignored.) }\r
+}\r
+\details{\r
+ This function displays or writes to disk the code to produce a table\r
+ associated with an object \code{x} of class \code{"xtable"}.\r
+ The resulting code is either a LaTeX or HTML table, depending on the\r
+ value of \code{type}. The function also (invisibly) returns a\r
+ character vector of the results (which can be helpful for\r
+ post-processing).\r
+\r
+ Since version 1.4 the non default behavior of \code{hline.after} is\r
+ changed. To obtain the same results as the previous versions add to\r
+ the \code{hline.after} vector the vector \code{c(-1, 0, nrow(x))}\r
+ where \code{nrow(x)} is the numbers of rows of the object.\r
+\r
+ From version 1.4-3, all non-numeric columns are sanitized, and all\r
+ LaTeX special characters are sanitized for LaTeX output. See Section\r
+ 3 of the \code{xtableGallery} vignette for an example of customizing\r
+ the sanitization. From version 1.4-4, the sanitization also applies to\r
+ column names. To remove any text sanitization, specify\r
+ \code{sanitize.text.function=function(x){x}}.\r
+\r
+ From version 1.6-1 the default values for the arguments other than\r
+ \code{x} are obtained using \code{getOption()}. Hence the user can\r
+ set the values once with \code{options()} rather than setting them in\r
+ every call to \code{print.xtable()}.\r
+\r
+ The argument \code{format.args} is used to supply arguments to the\r
+ \code{formatC} function, but will throw an error if values for\r
+ \code{digits} or \code{format} are included in the list of\r
+ arguments. The recommended approach to specify \code{digits} is to supply\r
+ the argument \code{digits} to \code{xtable}, and to specify\r
+ \code{format} supply the argument \code{display} to \code{xtable}. See\r
+ the examples.\r
+}\r
+\author{\r
+ David Dahl \email{dahl@stat.byu.edu} with contributions and\r
+ suggestions from many others (see source code).\r
+}\r
+\references{\r
+ Fairbairns, Robin (2005) \emph{Tables longer than a single page.} The\r
+ UK List of TeX Frequently Asked Questions on the\r
+ Web. \url{http://www.tex.ac.uk/cgi-bin/texfaq2html?label=longtab}\r
+}\r
+\seealso{\r
+ \code{\link{xtable}}, \code{\link{caption}}, \code{\link{label}},\r
+ \code{\link{align}}, \code{\link{digits}}, \code{\link{display}},\r
+ \code{\link{formatC}}\r
+}\r
+\r
+\examples{\r
+df <- data.frame(A = c(1.00123, 33.1, 6),\r
+ B = c(111111, 3333333, 3123.233))\r
+## The following code gives the error\r
+## formal argument "digits" matched by multiple actual arguments\r
+## print(xtable(df, display = c("s","e","e")),\r
+## format.args = list(digits = 3, big.mark = " ", decimal.mark = ","))\r
+## specify digits as argument to xtable instead\r
+print(xtable(df, display = c("s","f","f"), digits = 4),\r
+ format.args = list(big.mark = " ", decimal.mark = ","))\r
+## The following code gives the error\r
+## formal argument "format" matched by multiple actual arguments\r
+## print(xtable(df, digits = 4),\r
+## format.args = list(format = c("s","e","e"),\r
+## big.mark = " ", decimal.mark = ","))\r
+## specify format using display argument in xtable\r
+print(xtable(df, display = c("s","e","e"), digits = 4),\r
+ format.args = list(big.mark = " ", decimal.mark = ","))\r
+\r
+}\r
+\r
+\keyword{print}\r