Override default object display length in REPL/env?

If I want to display a large object (vector, array, matrix, etc) in the REPL, it will typically echo/display it, but incompletely with ellipses denoting the undisplayed/suppressed values.

Is there a way to override the length of the displayed object as a standard environment variable? It seems like this should be easy to do but I have not figured out a way to do it.

show() and @show will display an object but it’s just dumped without any formatting, which makes it difficult to read, and in any event, I have to do it on a case-by-case basis, rather than it being an environment/REPL setting.

I’ve tried using ENV[“LINES”] and setenv() but that doesn’t seem to work. Config() doesn’t seem to include anything related to this issue.

Any advice? It seems like this should be lurking somewhere in the REPL internals.

No, apparently there is no easy solution. The workarounds are:

  1. Use ; to avoid printing at all if you don’t want to see the data.

  2. If you actually know what you want to see, use slices:

julia> x = rand(300,300);

julia> x[1:3,1:3]
3×3 Matrix{Float64}:
 0.201148  0.343138  0.680792
 0.912477  0.670834  0.0462071
 0.497209  0.519856  0.501574

julia> x[1:2,:]
2×300 Matrix{Float64}:
 0.201148  0.343138  0.680792   0.250896  0.762277  …  0.947869  0.663313  0.331605  0.55514   0.69662
 0.912477  0.670834  0.0462071  0.866555  0.430131     0.705827  0.500807  0.28222   0.117387  0.232216

julia> x[end-2:end,:]
3×300 Matrix{Float64}:
 0.530914  0.288524  0.25518    0.719391  0.617756   …  0.754256  0.663696  0.624188  0.0637987  0.966756
 0.906517  0.724708  0.6759     0.756997  0.0216099     0.534473  0.709289  0.986315  0.733846   0.476186
 0.314051  0.712171  0.0621085  0.516785  0.563678      0.766445  0.79259   0.907545  0.46412    0.921298

  1. Edit the data: I sometimes use this function:
function edit!(x)
    tmp_file_name = tempname()
    writedlm(tmp_file_name,x)
    InteractiveUtils.edit(tmp_file_name)
    x .= readdlm(tmp_file_name)
end

With that, you can actually view the data and even edit it on your default text editor, with:

julia> x = rand(2,2)
2×2 Matrix{Float64}:
 0.987879  0.215942
 0.974738  0.975242

julia> edit!(x) # open vim and changed the first value to zero
2×2 Matrix{Float64}:
 0.0       0.215942
 0.974738  0.975242

2 Likes

Thanks. Your impression regarding lack of solutions is the same as mine. It’s surprising to me, as I’d think the default if anything would be to display the whole object, and that there would be an easy way to change the setting otherwise.

Slices sometimes works but sometimes you don’t really know.

I like your idea of the edit function. I’ve been trying it on my system; I can get it to open in an editor but then for some reason it usually crashes.

That specific function does not allow you to remove elements or other editions (because of the broadcasted reassignment of the values with .=). This is a little bit more general and perhaps useful, but has to be called with reassignment on return:

julia> using DelimitedFiles

julia> function edit!(x)
           tmp_file_name = tempname()
           writedlm(tmp_file_name,x)
           InteractiveUtils.edit(tmp_file_name)
           return readdlm(tmp_file_name)
       end
edit! (generic function with 1 method)

julia> x = rand(2,2)
2×2 Matrix{Float64}:
 0.913052  0.578263
 0.254731  0.435317

julia> x = edit!(x) # note the reassignment (removed first line)
1×2 Matrix{Float64}:
 0.254731  0.435317


The TerminalPager.jl package announced here is awesome for that purpose.

4 Likes

See Provide a simple way to print all entries in a collection · Issue #29223 · JuliaLang/julia · GitHub … in particular, you can do:

show(stdout, "text/plain", x)
1 Like

You can do this, possibly in .julia/config/startup.jl:

julia> Base.active_repl.options.iocontext[:displaysize] = (200, 2000)
(200, 2000)

julia> (1:100)'
1×100 adjoint(::UnitRange{Int64}) with eltype Int64:
 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

Thanks — these are all great suggestions and very helpful. I agree with some of the comments in that issue thread that this could be made easier to address in the Julia docs. A dedicated topic in the REPL section might help.