-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Provide a simple way to print all entries in a collection #29223
Comments
Maybe we should try to add some simple line break logic? |
Yeah, that would be ironic, but why not. #22847 said "This function has become pretty useless, since showing everything is basically the default." That's right, except for interactive use at the REPL. It wouldn't be totally absurd to me to have the convenience function
What do you mean? BTW, another context where one often needs to list names or entries is when looking at BenchmarkTools results (which is currently buggy, see JuliaCI/BenchmarkTools.jl#96). |
Actually, I realize the problem with the old |
Making the entries line up better. |
So that means making |
You can also do |
I'd like to emphasis that the current solution ( A typical reading flow trough the manual may look like this:
|
You can play with this example:
|
I completely agree, I have followed the same path.
giving :
instead of
|
Is it a typo @FerreolS? Should it be macro showall(expr)
quote
show(IOContext(stdout, :limit => false), "text/plain",$(esc(expr)))
end
end |
@singularitti Yes! you are right! something went wrong when I copy pasted my own startup.jl |
The NammedArrays example is now fixed. |
Is there a reason we've not just added @FerreolS 's #29223 (comment)
It does what I think it should and I'd appreciate having it. |
Why would you need a macro for this? Just |
It's more about remembering what to type than the typing itself - nothing in the text of Tho it is also long to type if I have to do it several times in a session. |
@tecosaur, would this be at home in About.jl? |
@jariji How about showall(x) = show(IOContext(stdout, :compact => false, :limit => false), "text/plain", x) It's the same thing. |
What I really want is a way to do
Nothing currently available is both easy to remember and guaranteed to show in the same format as the default show method AFAIK. |
|
Then using |
The way I was implementing this in #47520 was setting and unsetting The mechanism of a trailing character(s) to activate it wasn't popular, but perhaps that approach of wrapping the change in |
@LilithHafner I don't really think so, not without making it more complicated to use, and I'm trying to prioritise simplicity a bit. |
That will break with non-REPL displays, and it also seems problematic to mutate global state here (e.g. potentially creating a race condition in multithreaded code). One simple option would be to wrap the object to be displayed in an struct ShowAll
x
end
Base.show(io::IO, x::ShowAll) = show(IOContext(io, :limit=>false), x.x)
Base.show(io::IO, mime::MIME, x::ShowAll) = show(IOContext(io, :limit=>false), mime, x.x)
Base.show(io::IO, mime::MIME"text/plain", x::ShowAll) = show(IOContext(io, :limit=>false), mime, x.x) # fix method ambiguity
Base.showable(mime::MIME, x::ShowAll) = showable(mime, x.x)
Base.print(io::IO, x::ShowAll) = print(IOContext(io, :limit=>false), x.x) This works not only with the REPL but also with IJulia and other displays, and with other MIME types as long as they use the ( |
Re. the point about global state and multithreaded code, I was thinking of this as a REPL output modifier. Something that says do something different for this REPL evaluation output, so strictly serial.
An alternative is to make an options REPL mode, which was discussed in the other PR and triage at that time.
|
An options mode would also have the benefit of being able to guide the user, for discoverability
|
Alternatively, could it be viable to use Preferences.jl and make a nicer UI for interactively setting preferences? |
You could always hide the mechanics of this with another UI, e.g. displayall(x) = display(ShowAll(x))
This could be a UI for |
There is currently no simple way to print all entries in a collection (in particular in a vector) in a readable way. For example, if one wants to get all the column names in a table/data frame.
show(x)
prints a vector in full, but the entries are not aligned, making it quite painful to read on most terminals:Currently the only way to print all entries in a vertical layout is
show(stdout, "text/plain", x)
. It works well, but telling newcomers to write this just to see the list of columns in their table isn't terribly convincing, and it's very hard to discover.Can we do something about this? Intuitively I would have expected
show(x)
to be equivalent toshow(stdout, "text/plain", x)
(and haveprint(x)
do whatshow(x)
currently does), but it's kind of late to change this. Should we introduce a new convenience function, or a standardized keyword argument?FWIW, this issue also exists e.g. with DataFrames, where we support a few keyword arguments to easily decide whether to print all rows/columns (JuliaData/DataFrames.jl#1506).
The text was updated successfully, but these errors were encountered: