Unabridged printing of long strings, either in a Vector or in a DataFrame?

myersm0
Sat, 08 Jul 2023 20:33:54 +0000
General Usage

Sometimes when I’m working with long strings, usually in the form of a Vector{String}, I’d like to be able to see them in their entirety in the REPL, even if each one gets wrapped to multiple lines. Is there an easy way to override the default behavior and do this?

julia> mystrings = [repeat("abc", 64); repeat("def", 64); repeat("ghi", 64)]
3-element Vector{String}:
 "abcabcabcabcabcabcabcabcabcabca" ⋯ 131 bytes ⋯ "abcabcabcabcabcabcabcabcabcabc"
 "defdefdefdefdefdefdefdefdefdefd" ⋯ 131 bytes ⋯ "defdefdefdefdefdefdefdefdefdef"
 "ghighighighighighighighighighig" ⋯ 131 bytes ⋯ "ghighighighighighighighighighi"

Also, sometimes I have a column in a DataFrame that contains a long string, and I might wish for a print method that wraps the text in that column.

julia> using DataFrames
julia> mytest = DataFrame(col1 = 1:3, col2 = mystrings)
3×2 DataFrame
 Row │ col1   col2
     │ Int64  String
─────┼──────────────────────────────────────────
   1 │     1  abcabcabcabcabcabcabcabcabcabcab…
   2 │     2  defdefdefdefdefdefdefdefdefdefde…
   3 │     3  ghighighighighighighighighighigh…

Thanks in advance if anyone has advice on achieving one or both of these things.

7 posts - 4 participants