Shortcut to display an entire vector in the REPL

Is there a way to have the REPL not elide the middle elements from
the display of an array or vector?

This has probably been asked before but I can’t find the reference or a
solution. This is probably one of the pain points with julia for me as it
comes up all—the—time and it seems like there should be a resolution
for the issue by now.

The FAQ makes no mention. How have others solved the problem?

v = collect(1:1000)
show(v)
display(v)
println(v)

Or are you looking for a more permanent solution?

Is there a reason you need display to handle this instead of looping through elements and printing what you need?

Yes.

For a one-time thing, do show(stdout, "text/plain", array) to mimic the REPL output (which happens via display) but not limit output. Or just do show(array) or println(array) to get compact (single-line) non-truncated output.

To change the REPL display globally, you can change its IOContext (see the docs here):

Base.active_repl.options.iocontext[:limit] = false

See also the summary in the manual about how the different output functions interact: Output-function summary.

6 Likes

I’m looking for less work in the solution that preserves the standard REPL interface.

I want the REPL to “do what I want” here without extra effort.

This appears to do what I want. Keep the same REPL interactions but not
skipping the middle elements of large displays. It would be nice if the REPL
would allow you to toggle this as a feature.

Marking this as the solution and thanks for all the reference information.

This works nicely with TerminalPager.jl (also, if you have terminal pager active
then the context is no :limit-ed and you can see the entire set of data. You can
even scroll left and right. Unfortunately, I haven’t figured out a way to allow text
output to be handled by TerminalPager.jl but to allow graphics object through so
they are displayed (e.g. Makie figures).

It already does, no?

That being said, I would really like to see a better API here: julia#61005.

I’ve tried and failed before to come up with a shorthand for doing this in the repl. I think it would be good to figure that out.

2 Likes
macro p(ex)
    :(println($(esc(ex))))
end
DataArray1 = collect(1:100)

@p DataArray1
# 
julia> @p DataArray1
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100]```

[quote=“stevengj, post:8, topic:135580, full:true”]

It already does, no?

Not that I could find. In fact in the LTS 1.10.x julia it is the iocontext
option is listed as experimental.

I think it would help me if information on the REPL state were more
discoverable. For example, the standard varinfo() at the REPL prompt
doesn’t show anything tied to the REPL.

An empty help/? at the REPL does not return any information about the
REPL, just has references to julia as a language:

search: ] [ = $ ; ( @ { " ) ? . } ⊽ ⊼ ⊻ ⊋ ⊊ ⊉ ⊈ ⊇ ⊆ ≥ ≤ ≢ ≡ ≠ ≉ ≈ ∪ ∩ ∜ ∛ √ ∘ ∌ ∋ ∉ ∈ ℯ π ÷ ~ | ^ \ > < : / - + * ’ & % ! a && if :: as ‘’ ?: {} → () || do .= IO |>

Welcome to Julia 1.10.10. The full manual is available at

https://docs.julialang.org

as well as many great tutorials and learning resources:

Get started with Julia>

For help on a specific function or macro, type ? followed by its name, e.g. ?cos, or ?@time, and press enter. Type ; to enter shell mode, ] to enter package mode.

To exit the interactive session, type CTRL-D (press the control key together with the d key), or type exit().

It would be more useful if there were something like an repl entry that
could be looked at or even ?repl to give information on various options
and features. Maybe a reference to the varinfo() too?

In addition to other suggestions, and for those who generally prefer truncated output, a reasonably easy way to print all elements of a vector is

foreach(println, v)