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

**URL:** <https://discourse.julialang.org/t/unabridged-printing-of-long-strings-either-in-a-vector-or-in-a-dataframe/101365>\
**Category:** General Usage\
**Tags:** dataframes, io, prettytables\
**Created:** [July 8, 2023, 8:33pm UTC](https://discourse.julialang.org/t/unabridged-printing-of-long-strings-either-in-a-vector-or-in-a-dataframe/101365 "2023-07-08T20:33:54Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![myersm0](https://avatars.discourse-cdn.com/v4/letter/m/c5a1d2/32.png) [@myersm0](https://discourse.julialang.org/u/myersm0)\
**Post date:** [July 8, 2023, 8:33pm UTC](https://discourse.julialang.org/t/unabridged-printing-of-long-strings-either-in-a-vector-or-in-a-dataframe/101365/1 "2023-07-08T20:33:54Z")

</div>

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
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
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.

---

<div class="post-metadata">

**Author:** ![myersm0](https://avatars.discourse-cdn.com/v4/letter/m/c5a1d2/32.png) [@myersm0](https://discourse.julialang.org/u/myersm0)\
**Post date:** [July 8, 2023, 8:48pm UTC](https://discourse.julialang.org/t/unabridged-printing-of-long-strings-either-in-a-vector-or-in-a-dataframe/101365/2 "2023-07-08T20:48:11Z")

</div>

I think the answer to the first scenario is probably something like:

```julia

function Base.show(io::IO, ::MIME"text/plain", v::Vector{String})
    for i in eachindex(v)
        println(v[i])
    end
end

```

---

<div class="post-metadata">

**Author:** ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)\
**Post date:** [July 9, 2023, 1:23pm UTC](https://discourse.julialang.org/t/unabridged-printing-of-long-strings-either-in-a-vector-or-in-a-dataframe/101365/3 "2023-07-09T13:23:49Z")

</div>

> [@myersm0](#):
>
> 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

You can use [PrettyTables.jl](https://ronisbr.github.io/PrettyTables.jl/stable/):

```julia
using DataFrames, PrettyTables
mytest = DataFrame(col1=1:3, col2=mystrings)
pretty_table(mytest,columns_width=[8,60], autowrap=true, crop=:none)

```

For vectors of long strings, simply do: `println.(mystrings);`

---

<div class="post-metadata">

**Author:** ![bkamins](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bkamins/32/208538_2.png) [@bkamins](https://discourse.julialang.org/u/bkamins)\
**Post date:** [July 9, 2023, 1:43pm UTC](https://discourse.julialang.org/t/unabridged-printing-of-long-strings-either-in-a-vector-or-in-a-dataframe/101365/4 "2023-07-09T13:43:11Z")

</div>

PrettyTables.jl is re-exported by DataFrames.jl, so one could just call `PrettyTables.pretty_table`. Alternatively you also can just call `show` as DataFrames.jl uses PrettyTables.jl internally:

```julia
julia> show(mytest,columns_width=[8,60], autowrap=true)
3×2 DataFrame
 Row │ col1 col2
     │ Int64 String
─────┼────────────────────────────────────────────────────────────────────────
   1 │ 1 abcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabc
     │ abcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabc
     │ abcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabc
     │ abcabcabcabc
   2 │ 2 defdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdef
     │ defdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdef
     │ defdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdefdef
     │ defdefdefdef
   3 │ 3 ghighighighighighighighighighighighighighighighighighighighi
     │ ghighighighighighighighighighighighighighighighighighighighi
     │ ghighighighighighighighighighighighighighighighighighighighi
     │ ghighighighi

```

@Ronis_BR - I think something along the lines of this example would be nice to include in the manual section on printing, as it is a quite common need.

---

<div class="post-metadata">

**Author:** ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)\
**Post date:** [July 9, 2023, 1:46pm UTC](https://discourse.julialang.org/t/unabridged-printing-of-long-strings-either-in-a-vector-or-in-a-dataframe/101365/5 "2023-07-09T13:46:40Z")

</div>

I think we also need to pass: `crop=:none`, otherwise if the table is long or the REPL height is short, it will not print all rows.

---

<div class="post-metadata">

**Author:** ![myersm0](https://avatars.discourse-cdn.com/v4/letter/m/c5a1d2/32.png) [@myersm0](https://discourse.julialang.org/u/myersm0)\
**Post date:** [July 9, 2023, 3:23pm UTC](https://discourse.julialang.org/t/unabridged-printing-of-long-strings-either-in-a-vector-or-in-a-dataframe/101365/6 "2023-07-09T15:23:59Z")

</div>

Thanks to you both, I wasn’t aware of PrettyTables.

---

<div class="post-metadata">

**Author:** ![Ronis\_BR](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ronis_br/32/50999_2.png) [@Ronis\_BR](https://discourse.julialang.org/u/Ronis_BR)\
**Post date:** [July 11, 2023, 12:32pm UTC](https://discourse.julialang.org/t/unabridged-printing-of-long-strings-either-in-a-vector-or-in-a-dataframe/101365/7 "2023-07-11T12:32:00Z")

</div>

Yes! I really need to find time to write that documentation. I am sorry for the delay. I entered a rabbit hole of splitting SatelliteToolbox.jl into smaller packages that took **way** more time than anticipated. Everything is almost finished and I will be able to take care of other packages really soon 🙂
