GithubHelp home page GithubHelp logo

Comments (6)

DarwinAwardWinner avatar DarwinAwardWinner commented on August 17, 2024

I had a look through the code to see if I could implement this myself, but there were a few too many layers of indirection for me to follow. If you can point me to the appropriate place in the code, I can try implementing this when I have time.

from pillar.

krlmlr avatar krlmlr commented on August 17, 2024

Thanks. The prt package implements output in this way, see, e.g., https://github.com/nbenn/prt/blob/main/tests/testthat/_snaps/format.md .

CC @nbenn.

from pillar.

DarwinAwardWinner avatar DarwinAwardWinner commented on August 17, 2024

Interesting. So it looks like I could potentially define my own print method for data frames and/or tibbles that calls prt::format_dt. Is there an easy way to determine if a given tibble's backend supports efficient random access so that I can avoid trying to e.g. get the tail of a database query result?

from pillar.

krlmlr avatar krlmlr commented on August 17, 2024

None that I'm aware of, perhaps you could implement some heuristics? Happy to review if you'd be willing to share an implementation.

from pillar.

DarwinAwardWinner avatar DarwinAwardWinner commented on August 17, 2024

I will definitely share if I figure it out. Do you have any opinions on how the options should be set up?

from pillar.

DarwinAwardWinner avatar DarwinAwardWinner commented on August 17, 2024

A minimal implementation for tibbles, meant to be put in ~/.Rprofile:

print.tbl <- function (x, width = NULL, ..., n = NULL, max_extra_cols = NULL, max_footer_lines = NULL) {
    tryCatch({
        n_half <- if(!is.null(n)) ceiling(n/2)
        prt:::cat_line(prt:::format_dt(x = x, ..., n = n_half, width = width, max_extra_cols = max_extra_cols, max_footer_lines = max_footer_lines))
    }, error = \(...) pillar:::print.tbl(x = x, width = width, ..., n = n, max_extra_cols = max_extra_cols, max_footer_lines = max_footer_lines))
}

I also came up with something for base data frames, but I print them using the aforementioned S4Vectors code, since the dplyr/pillar stuff doesn't print row names, which can't be ignored for base data frames.

print.data.frame <- function(x, ...) {
    tryCatch({
        withr::with_options(
            list(max.print = ncol(x) * 15),
            S4Vectors:::.show_DataFrame(x)
        )
    }, error = \(...) base::print.data.frame(x = x, ...))
}

from pillar.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.