Why won't `cat` append to a `file` connection?

r

Solution

Because that's what `?cat` says it will do if `file` is not the name of a file.

append: logical. Only used if the argument 'file' is the name of file (and not a connection or '"|cmd"'). If 'TRUE' output will be appended to 'file'; otherwise, it will overwrite the contents of 'file'.

Problem

I ran these two code blocks, expecting the same output ``` cattest <- file("cattest.txt") cat("First thing", file = cattest) cat("Second thing", file = cattest, append = TRUE) close(cattest) sink("cattest_sink.txt") cat("First thing") cat("Second thing") sink() ``` But the resulting `cattest.txt` contains only "Second thing", whereas the `cattest_sink.txt` includes what I expected, "First thingSecond thing". Why is the `append` argument ignored with the file connection? I'm on 64bit R 3.0.1 on Windows, in case it matters.

Original source