displaying the NamedArray without the summary
Closed this issue · 6 comments
More of a question than a bug.
I could not find a way to display the NamedArray to io without the summary (for instance2×4 Named Matrix{Float64}
).
I am currently doing println(io, mynamedarray
).
I am using NamedArrays v0.9.6.
Is there a way to do it?
You could write println(io, mynamedarray.array)
or println(io, Array(mynamedarray))
.
My bad, I should have written a complete example.
using NamedArrays
n = NamedArray(rand(2,4))
setnames!(n, ["one", "two"], 1)
setnames!(n, ["A", "B", "C", "D"], 2)
setdimnames!(n, ("Num", "Letters"))
println(n)
gives
2×4 Named Matrix{Float64}
Num ╲ Letters │ A B C D
──────────────┼───────────────────────────────────────────────
one │ 0.369821 0.00162868 0.644479 0.877991
two │ 0.916525 0.303063 0.29275 0.628001
but I would like to get that:
Num ╲ Letters │ A B C D
──────────────┼───────────────────────────────────────────────
one │ 0.369821 0.00162868 0.644479 0.877991
two │ 0.916525 0.303063 0.29275 0.628001
where 2×4 Named Matrix{Float64}
is not displayed.
The reason being that I would like the person reading through the table not to be distracted by the information about the size and type of the data presented.
OK, I now see that ordinary arrays do not print to a nicely formatted set of lines.
That is probably a task for show
or display
I think I have shortcut them to be all the same.
If print()
is supposed to give a character representation of the object, I need to include the names of the indices and dimensions, too. So it probably is going to return a tuple, then. Something like
([0.369821 0.00162868 0.644479 0.877991; 0.916525 0.303063 0.29275 0.628001], ["one", "two"], ["A", "B", "C", "D"], ["Num", "Letters"])
Is this going to be more like what you'd want?
Hi @davidavdav,
Thanks for taking the time to look at this topic. I am sorry, as it seems that I am not conveying my issue quite rightly.
I am okay with almost everything 😀.
I particularly like how the tables are nicely formatted because it eases reading the content. The final output in my previous comment is the target I am trying to achieve.
Your code in the overriding of the show
function is almost producing it. Except that at the beginning, there is a presentation of a "summary" of the table (the type and size of the elements), which I would like not to present to the user.
If you don't want to change the show
, it is also fine. I understand that other users could have different needs. If so, just let me know. If that is the case, I am considering making a clone of the package with the only difference that it won't display the small "summary" at the beginning. It seems straightforward to do: as it is only a few lines to delete. It just seems a bit inelegant to make a new package just for that purpose.
I was inquiring if this summary is desired as it is about the metadata about the array instead of only the array content (a lot seemed to me that the information is more for a developer who will need to use the data in some way rather than the one interested in analysing the content). I initially thought about passing an extra parameter to let the caller choose if he wants the initial summary, but in that case the function won't override the Base one.
If it is possible to make a different behaviour for show
and display
it will be great then I could use one without the summary.
I will try to edit that comment to add a reference to the summary call.
Line 28 in b6d4e92
I hope this clarifies the issue.
I understand what you want. I am not going to remove the type annotation for display
, because regular Julia types do this as well. So your solution is in a wrapper that writes to a string buffer, and then remove the first line from that string buffer.
function myprint(io::IO, n::NamedArray)
tmpio = IOBuffer()
show(tmpio, n)
print(io, split(String(take!(tmpio)), "\n", limit=2)[2])
end
When I understand the print/show/display
split (probably not any time soon, every time I try to understand this I fail to do so), they are probably going to look like more like their Array counterparts.
Excellent!
Well, when you understand the print show display
please keep a way to have the current nice printout.