Is there a julia equivalent of R's sink() function?

From time to time I would like to verbatim redirect output normally shown in the julia REPL to a text file. In R I do this by

sink('txtfile.txt')
interestingfunctionwithoutputs()
sink()

Does something like this exist in julia? The use case in this case is piping out the output from UnicodePlots to a text file without manually copy pasting.

I don’t really see the need to redirect any output here, you can just use

julia> plt = lineplot([-1, 2, 3, 7], [-1, 2, 9, 4]);

julia> open("plot", "w") do io
           show(io, plt)
       end  

For actually redirecting stdout there is the redirect_stdout function.

2 Likes

Didn’t think of that. Indeed that fits the bill.