[R] sink() not working as expected

Ivan Krylov
Tue, 02 Nov 2021 21:21:21 -0000

On Tue, 2 Nov 2021 10:18:07 -0700 (PDT)
Rich Shepard <rshepard at appl-ecosys.com> wrote:

> 'corvalis discharge summary\n'
> summary(cor_disc)
> sd(cor_disc$cfs)
> '-----------------\n'

In the interactive mode, on the top level of execution, these commands
behave as if you had written

print(sink('data-summaries.txt'))
print('corvalis discharge summary\n')
print(summary(cor_disc))
print(sd(cor_disc$cfs))

instead. When you source() a script, auto-printing is not performed.
This is explained in the first paragraph of ?source, but not ?sink. If
you want to source() scripts and rely on their output (including
sink()), you'll need to print() results explicitly.

--
Best regards,
Ivan