I would like to get the output like it is printed in the Julia REPL as a string, without printing to a REPL.
Consider you have a large matrix x.
x = rand(100, 100)
In the REPL, x is displayed in a nice way. I would like to get this output as a string with a function call (not in a hacky way). How can I do this?
I tried to use the function repr to get the output:
repr(x)
This gives a very long string, containing all the numbers and cluttering the screen.
I tried to use the context argument.
At first with the displaysize key:
repr(x, context = :displaysize => (80,80))
It doesn't have any effect. (?)
I try to use the limit key:
repr(x, context = :limit => true)
This gives an output which doesn't clutter the screen any more but it doesn't look as nice as the "normal" REPL output.
I tried the same with the print function and an IOContext
io = IOBuffer();
print(IOContext(io, :limit => true), x)
String(take!(io))
This gives the same result as repr.