Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make CoefTable width adjustable #794

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

wildart
Copy link
Contributor

@wildart wildart commented May 29, 2022

Large tables tend to mess output by wrapping lines. See JuliaStats/MultivariateStats.jl#186.

This PR make CoefTable width adjustable by omitting columns that are not fit into the screen.

julia> displaysize(stdout)
(40, 85)

julia> ct = CoefTable(rand(3,7), ["c$i" for i in 1:7], [], 4)
───────────────────────────────────────────────────────────────────────
           c1        c2        c3      c4        c5        c6        c7
───────────────────────────────────────────────────────────────────────
[1]  0.509143  0.331133  0.472937  0.2931  0.259103  0.276718  0.546421
[2]  0.333433  0.403466  0.734801  0.0767  0.252618  0.565498  0.513081
[3]  0.630933  0.855958  0.181175  0.1445  0.246145  0.411041  0.377053
───────────────────────────────────────────────────────────────────────

julia> displaysize(stdout) # reduced terminal width
(40, 69)

julia> ct
─────────────────────────────────────────────────────────
           c1        c2        c3      c4        c5     
─────────────────────────────────────────────────────────
[1]  0.509143  0.331133  0.472937  0.2931  0.259103     
[2]  0.333433  0.403466  0.734801  0.0767  0.252618     
[3]  0.630933  0.855958  0.181175  0.1445  0.246145     
─────────────────────────────────────────────────────────

julia> displaysize(stdout)  # reduced terminal width
(40, 38)

julia> ct
─────────────────────────────
           c1        c2     
─────────────────────────────
[1]  0.509143  0.331133     
[2]  0.333433  0.403466     
[3]  0.630933  0.855958     
─────────────────────────────

julia> show(IOContext(stdout, :limit=>false), ct)
───────────────────────────────────────────────────────────────────────
           c1        c2        c3      c4        c5        c6        c7
───────────────────────────────────────────────────────────────────────
[1]  0.509143  0.331133  0.472937  0.2931  0.259103  0.276718  0.546421
[2]  0.333433  0.403466  0.734801  0.0767  0.252618  0.565498  0.513081
[3]  0.630933  0.855958  0.181175  0.1445  0.246145  0.411041  0.377053
───────────────────────────────────────────────────────────────────────

Copy link
Member

@nalimilan nalimilan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

test/statmodels.jl Outdated Show resolved Hide resolved
src/statmodels.jl Outdated Show resolved Hide resolved
src/statmodels.jl Outdated Show resolved Hide resolved
src/statmodels.jl Outdated Show resolved Hide resolved
src/statmodels.jl Outdated Show resolved Hide resolved
@nalimilan
Copy link
Member

Would it be possible to print fewer hdots? Matrices and data frames print only one every 5-6 rows.

@wildart
Copy link
Contributor Author

wildart commented Sep 16, 2022

@nalimilan ready for another review round.

src/statmodels.jl Outdated Show resolved Hide resolved
Comment on lines +85 to +89
ct = CoefTable(rand(15,100), ["c$i" for i in 1:100], [], 4)
sct = sprint(show, ct, context=:limit=>false)
@test textwidth(first(split(sct, '\n'))) > 900
sct = sprint(show, ct, context=:limit=>true)
@test textwidth(first(split(sct, '\n'))) <= displaysize()[2]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Haven't you found a way to test the exact output as discussed above?

Copy link
Contributor Author

@wildart wildart Oct 9, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The displaysize() returns current terminal dimensions, what ever they may be in the CI environment. I would assume standard 80x25.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes I think it's same to assume that, and check the string output for these dimensions.

Co-authored-by: Milan Bouchet-Valat <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants