On Wed, Oct 30, 2013 at 6:22 PM, Hadley Wickham <h.wick...@gmail.com> wrote: > Hi all, > > Can anyone help me understand why an implicit print (i.e. just typing > df at the console), is so much slower than an explicit print (i.e. > print(df)) in the example below? I see the difference in both Rstudio > and in a terminal. > > # Construct large df as quickly as possible > dummy <- 1:18e6 > df <- lapply(1:10, function(x) dummy) > names(df) <- letters[1:10] > class(df) <- c("myobj", "data.frame") > attr(df, "row.names") <- .set_row_names(18e6) > > print.myobj <- function(x, ...) { > print.data.frame(head(x, 2)) > } > > start <- proc.time(); df; flush.console(); proc.time() - start > # user system elapsed > # 0.408 0.557 0.965 > start <- proc.time(); print(df); flush.console(); proc.time() - start > # user system elapsed > # 0.019 0.002 0.020
If I change print(df) to print.data.frame(df) it hangs. R version 3.0.2 Patched (2013-10-06 r64031) -- "Frisbee Sailing" Copyright (C) 2013 The R Foundation for Statistical Computing Platform: x86_64-w64-mingw32/x64 (64-bit) ______________________________________________ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel