What exactly does split do in the sink()
function? No website or video seems to explain it explicitly.
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\""