Skip to content

Commit

Permalink
Removed deprecated function toLatex.table
Browse files Browse the repository at this point in the history
  • Loading branch information
hofnerb committed Nov 26, 2015
1 parent 65ec50f commit 21eacba
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 120 deletions.
114 changes: 0 additions & 114 deletions R/summarize.R
Original file line number Diff line number Diff line change
Expand Up @@ -629,117 +629,3 @@ print.summary <- function(x, ...) {
}
NextMethod("print")
}

## can we use xtable to produce this output?
## rules perhaps can be added using the add.to.rows = list(pos = c(), command = rep(rules, ...))
toLatex.table <- function(object,
table = c("tabular", "longtable"),
align = NULL,
caption = NULL,
label = NULL,
floating = FALSE,
center = TRUE,
colnames = get_option(object, "colnames"),
rules = get_option(object, "rules"),
sep = get_option(object, "sep"),
sanitize = get_option(object, "sanitize"),
header = get_option(object, "header")) {

warning("This function is deprecated and will be removed eventually")

table <- match.arg(table)
tab <- object

cat("%% Output requires \\usepackage{booktabs}.\n")
if (table == "longtable")
cat("%% Output requires \\usepackage{longtable}.\n")
if (floating) {
if (table == "longtable") {
warning(sQuote("floating = TRUE"), " cannot be used with ",
dQuote("longtable"))
} else {
cat("\\begin{table}")
if (!is.null(caption))
cat(" \\caption{", caption, "}\n\n")
if (!is.null(label))
cat(" \\label{", label, "}\n\n")
if (center)
cat("\\begin{center}\n")
}
} else {
if (!is.null(caption)) {
if (table == "longtable") {
if (center)
cat("\\begin{center}\n")
cat("\\begin{", table,"}{", align, "} \n", sep ="")
cat(" \\caption{", caption, "}\n")
if (!is.null(label))
cat(" \\label{", label, "}\n")
cat("\\\\[-1em]\n")
} else {
cat("%% Output requires \\usepackage{capt-of}.\n")
## use end minipage to group caption and table
cat("\\begin{minipage}{\\linewidth}\n")
if (center)
cat("\\begin{center}\n")
cat(" \\captionof{table}{", caption, "}\n")
if (!is.null(label))
cat(" \\label{", label, "}\n")
#if (center)
# cat(" \\vspace*{-1em}\n")
cat("\\begin{", table,"}{", align, "} \n", sep ="")
}
} else {
if (center)
cat("\\begin{center}\n")
cat("\\begin{", table,"}{", align, "} \n", sep ="")
}
}
cat(" \\toprule \n")

if (!is.null(header))
cat(header, " \n")

cat(paste(colnames, collapse = " & "), "\\\\ \n")
cat(rules)
if (table == "longtable")
cat(" \\endhead \n")

## Convert to character strings
tab <- apply(tab, 2, function(x)
ifelse(sapply(x, is.numeric), sprintf("%4.2f", x), x))
## if tab accidentially drops to a vector
if (is.null(dim(tab)))
tab <- matrix(tab, nrow = 1)

# tab[,1] <- gsub("(_)", "\\\\_", tab[,1])
if (is.function(is.function(sanitize))) {
toLatex <- sanitize
sanitize <- TRUE
}
if (is.logical(sanitize) && sanitize == TRUE)
tab <- apply(tab, 2, toLatex)
## if tab accidentially drops to a vector
if (is.null(dim(tab)))
tab <- matrix(tab, nrow = 1)

## if separators should be added after each factor variable:
if (sep == TRUE) {
tab[tab[,1] != "", 1][-1] <- paste(rules, tab[tab[,1] != "", 1][-1])
}

## Replace NA with " "
tab[is.na(tab)] <- ""
out <- apply(tab, 1, function(x)
cat(paste(x, collapse = " & "), " \\\\ \n"))
cat(" \\bottomrule \n")

cat("\\end{", table, "} \n\n", sep ="")
if (center)
cat("\\end{center}\n")
if (floating && table != "longtable")
cat("\\end{table}\n\n")
## if captionof is used end minipage
if (!floating && table != "longtable" && !is.null(caption))
cat("\\end{minipage}\n")
}
6 changes: 0 additions & 6 deletions tests/regtest-summarize.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ if (require("nlme")) {
summarize(Orthodont, quantiles = FALSE, type = "numeric")
summarize(Orthodont, quantiles = FALSE, count = FALSE, type = "numeric")
(tmp <- summarize(Orthodont, mean_sd = FALSE, type = "numeric"))
## print summary as LaTeX object
papeR:::toLatex.table(tmp)

## Get summary for categorical variables
(tab2 <- summarize(Orthodont, type = "fac"))
Expand All @@ -41,13 +39,9 @@ if (require("nlme")) {
if (require("xtable")) {
ans <- xtable(tab1)
print(ans)
papeR:::toLatex.table(tab1)

## grouped
xtable(summarize(Orthodont, group = "Sex"))

print(xtable(tab2))
papeR:::toLatex.table(tab2)
}
}

0 comments on commit 21eacba

Please sign in to comment.