Specifying a file as the 'stdout' argument of the 'system2' function does not work in Rgui on windows. It does work for Rscript and R.exe on the same system.
system2("whoami", stdout="out.txt", stderr="err.txt")
See also this thread on r-devel: http://r.789695.n4.nabble.com/Redirect-system2-stdout-to-a-file-on-windows-td4671543.html
First, the example is not reproducible. There is no 'whoami' command on Windows (at least, not in my sole copy).
Second, it cannot be major: it works correctly with basic R: it is only an issue in the GUI.
A similar function now works correctly. But this would not be the first time the issue was with a particular executable.
I just tried this using "attrib" instead of "whoami", and it was fine. (attrib.exe is a standard Windows executable). I also tried "whoami" from Cygwin, and it also worked. So I agree with Brian that the problem is with whatever "whoami" executable you were using.
You seem to be right that the problem does not occur for every executable, but it is not limited to whoami (which was perhaps an unfortunate example). More users have been experiencing a related issue with other programs, e.g. http://stackoverflow.com/questions/18080378/tm-readpdf-error-in-filecon-r-cannot-open-the-connection.
Actually it seems to be the happening for the R executable itself as well. The reason why I came to this problem was because I am trying to capture output from install.packages(). Because sink() and capture.output() don't work, I tried something like this:
system2("R", c("CMD", "INSTALL", "MASS_7.3-28.tar.gz"), stdout="out.txt", stderr="err.txt")
This will prevent stdout and stderr to be printed to the console, but no files are created (at least I couldn't find them).
Thanks, the example with R is very useful. I'll see if I can reproduce it and identify what's going wrong.
I can't confirm the bug in R-patched or R-devel using your R CMD INSTALL example, though I do see it in 3.0.1. Could you please try R-patched?
The problem seems to have disappeared in R patched indeed.
This was fixed in r63697 by Brian Ripley.
Created attachment 1526 [details]
paper for example
(spam comment removed)