Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What exactly does split do in the sink() function?

Tags:

split

r

sink

What exactly does split do in the sink() function? No website or video seems to explain it explicitly.

like image 611
AS_392 Avatar asked Feb 19 '26 06:02

AS_392


1 Answers

From ?sink:

   split: logical: if 'TRUE', output will be sent to the new sink and
          to the current output stream, like the Unix program 'tee'.

Normally, sink gives you the user no output, sending it all to a file. With split=TRUE, it gives you all of the output (seemingly normal) and dumps the output to the file.

# non-split behavior
sink("quux1.txt")
1+2
print("hello")
sink(NULL)
readLines("quux1.txt")
# [1] "[1] 3"         "[1] \"hello\""

# split behavior
sink("quux2.txt", split = TRUE)
1+3
# [1] 4
print("hello again")
# [1] "hello again"
sink(NULL)
readLines("quux2.txt")
# [1] "[1] 4"               "[1] \"hello again\""
like image 114
r2evans Avatar answered Feb 20 '26 23:02

r2evans



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!