[Bioc-devel] Use DataFrame's printing format for data.frames
Ryan C. Thompson
rct at thompsonclan.org
Sat Nov 17 22:10:06 CET 2012
Hi all,
I noticed that DataFrame objects have a much faster and more practical
printing format than base R's data.frame class. So I wrote a replacement
for "print.data.frame" that prints data.frames in the same style as
DataFrames. Just stick it in your ~/.Rprofile and your data.frames will
magically print like DataFrames.
print.data.frame <- function(df) {
if (require("IRanges")) {
prev.max.print <- getOption("max.print")
on.exit(options(max.print=prev.max.print))
options(max.print=ncol(df) * 20)
x <- capture.output(print(as(df, "DataFrame")))
cat(str_replace(x[[1]], "DataFrame", "data.frame"),
x[-1],
sep="\n")
} else {
base::print.data.frame(df)
}
}
More information about the Bioc-devel
mailing list