[Rd] Code Optimization: print.data.frame + as.data.frame(head(x, n = options("max.print")))
Juan Telleria Ruiz de Aguirre
jtelleri@@rproject @ending from gm@il@com
Tue Jul 31 08:19:33 CEST 2018
I polished a little bit more the function:
* Used: getOption("max.print")
* Added comment at the end: cat('[ reached getOption("max.print") --
omitted ', omitted,' rows ]')
function (x, ..., digits = NULL, quote = FALSE, right = TRUE,
row.names = TRUE)
{
n <- length(row.names(x))
if (length(x) == 0L) {
cat(sprintf(ngettext(n, "data frame with 0 columns and %d row",
"data frame with 0 columns and %d rows"), n), "\n",
sep = "")
}
else if (n == 0L) {
print.default(names(x), quote = FALSE)
cat(gettext("<0 rows> (or 0-length row.names)\n"))
}
else {
omitted <- nrow(x)-getOption("max.print")
x <- as.data.frame(head(x, n = getOption("max.print")))
m <- as.matrix(format.data.frame(x, digits = digits,
na.encode = FALSE))
if (!isTRUE(row.names))
dimnames(m)[[1L]] <- if (isFALSE(row.names))
rep.int("", n)
else row.names
print(m, ..., quote = quote, right = right)
if((nrow(x)-getOption("max.print"))>0){
cat('[ reached getOption("max.print") -- omitted ', omitted,' rows ]')
}
}
invisible(x)
}
[[alternative HTML version deleted]]
More information about the R-devel
mailing list