1

Edit: This problem doesn't seem to be reproducible at this point, but I've updated this question to a more concise example that illustrates what the behavior was, in case anyone encounters a similar issue.

sink("res4.txt")
    cat("Here are my results:\n")
    summary(mtcars)
sink()

The sink("~/R/res4.txt") function in the last line will store the "Here are my results" line, but not the summary(res4) line in the .txt file.

Typing summary(mtcars) produces the correct data set, and I don't understand why the output of summary(mtcars) isn't included.

Mako212
  • 6,787
  • 1
  • 18
  • 37
  • 1
    Are you running this non-interactively? Do you mean to have `print(summary(res4))`? – MrFlick Jan 05 '15 at 23:22
  • @MrFlick Thanks, that works. I didn't realize that I needed the `print` function because `summary(res4)` generates the same output in the console. – Mako212 Jan 07 '15 at 01:38

1 Answers1

8

There are as many summary functions as there are regression procedures and many of them use cat with would not get into a value returned. My suggestion is to use cat and capture.output both of which have a file destination parameter and an append option:

cat("Here are my results:\n", file="~/R/res4.txt")
capture.output( summary(res4), file"~/R/res4.txt", append=TRUE)
IRTFM
  • 258,963
  • 21
  • 364
  • 487
  • Greate, the "capture.output" function circumvents problems related to "sink" in bat mode and Rnoweb! – jcfaria Jun 10 '18 at 15:38