[R] sink() not working as expected

Andrew Simmons @kw@|mmo @end|ng |rom gm@||@com
Tue Nov 2 22:31:12 CET 2021

cat in R behaves similarly to cat in unix-alikes, sends text to a stdout.
Usually, that stdout would be a file, but usually in R it is the R Console.
I think it might also help to note the difference between cat and print:

x <- "test\n"


> cat(x)
> print(x)
[1] "test\n"

With that said, wrap each expressions in cat or print depending on which
you want. Also, I would probably add a tryCatch with argument finally as {
which will guarantee the file connection is severed, even if an error is
raised. Hope this helps

On Tue, Nov 2, 2021, 15:52 Rich Shepard <rshepard using appl-ecosys.com> wrote:

> On Tue, 2 Nov 2021, Bert Gunter wrote:
> > What do you think these 2 lines are doing?
> > cat ('corvalis discharge summary\n')
> > print(cat)
> Bert,
> If I used them in linux cat would display the file (as do more and less)
> and
> print() would be replaced with lpr
> > Please consult ?cat . You might also spend a bit of (more?) time with an
> R
> > tutorial or two as you seem confused about how assignment (<-) works. Or
> > maybe I'm confused about what is confusing you....
> Having never before needed to use cat in R, and not seeing it explained in
> the one sink() web page, I didn't think to look at the help page.
> Now, using cat and not print line-by-line the first set of commands work,
> but not the second.
> More reading coming up.
> Rich
> ______________________________________________
> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

	[[alternative HTML version deleted]]

More information about the R-help mailing list