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

**URL:** <https://discourse.julialang.org/t/is-there-a-julia-equivalent-of-rs-sink-function/27675>\
**Category:** New to Julia\
**Tags:** question\
**Created:** [August 18, 2019, 8:04am UTC](https://discourse.julialang.org/t/is-there-a-julia-equivalent-of-rs-sink-function/27675 "2019-08-18T08:04:45Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![DoktorMike](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/doktormike/32/2736_2.png) [@DoktorMike](https://discourse.julialang.org/u/DoktorMike)\
**Post date:** [August 18, 2019, 8:04am UTC](https://discourse.julialang.org/t/is-there-a-julia-equivalent-of-rs-sink-function/27675/1 "2019-08-18T08:04:45Z")

</div>

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

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

---

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [August 18, 2019, 8:25am UTC](https://discourse.julialang.org/t/is-there-a-julia-equivalent-of-rs-sink-function/27675/2 "2019-08-18T08:25:08Z")

</div>

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

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

---

<div class="post-metadata">

**Author:** ![DoktorMike](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/doktormike/32/2736_2.png) [@DoktorMike](https://discourse.julialang.org/u/DoktorMike)\
**Post date:** [August 18, 2019, 6:00pm UTC](https://discourse.julialang.org/t/is-there-a-julia-equivalent-of-rs-sink-function/27675/3 "2019-08-18T18:00:38Z")

</div>

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