Hi Keith, The problem is not with tempfile(), and is not really a problem of whether a file exists or not. The problem is that system2() does not put the contents of stderr into the file. Here is a demonstration without the use of tempfile(), using a pre-existing output file:
klediment:~ dante$ echo "Hello" > output.txt klediment:~ dante$ cat output.txt Hello klediment:~ dante$ R -q > system2("./test.rb", stderr="output.txt") stderrstdout> q("no") # should only see "stdout" in console, "stderr" should go to file klediment:~ dante$ cat output.txt Hello klediment:~ dante$ R -q > system2("./test.rb", stdout="output.txt") # works correctly stderr> q("no") klediment:~ dante$ cat output.txt stdoutklediment:~ dante$ My sessionInfo() follows, but I got the identical behavior on R 2.12 (release version) and R 2.13. Thanks, Dan > sessionInfo() R version 2.12.0 Patched (2010-10-15 r53335) Platform: x86_64-apple-darwin9.8.0/x86_64 (64-bit) locale: [1] en_US.UTF-8/en_US.UTF-8/C/C/en_US.UTF-8/en_US.UTF-8 attached base packages: [1] stats graphics grDevices utils datasets methods base On Wed, Nov 10, 2010 at 7:33 PM, Keith Satterley <ke...@wehi.edu.au> wrote: > Looking at help for tempfile, > > "tempfile" returns a vector of character strings which can be used as names > for temporary files. > > and > > For "tempfile" a character vector giving the names of possible > (temporary) files. Note that no files are generated by "tempfile". > > > try a file.create(t) after tempfile() > > cheers, > > Keith > > > Dan Tenenbaum wrote: > >> According to ?system2, I should be able to direct the output of STDERR to >> a >> file by giving the filename as a character vector to the "stderr" >> argument. >> >> But here is what happens. >> >> Given a ruby script test.rb (with its executable bit set): >> >> #!/usr/bin/env ruby >> STDOUT.puts "stdout" >> STDERR.puts "stderr" >> >> And the following R code: >> >> >> >>> t <- tempfile() >>> res <- system2("./test.rb", stdout=TRUE, stderr=t) >>> >>> >> stderr >> >> >>> res >>> >>> >> [1] "stdout" >> >> >>> file.exists(t) >>> >>> >> [1] FALSE >> >> I would expect the file t to exist and contain "stderr", and I would >> expect >> not to see "stderr" in the console. >> >> Also, there is a typo in the man page - the command is listed as "system" >> in >> the Description instead of "system2". >> >> The reverse behavior does work correctly: >> >> >>> res <- system2("./test.rb", stdout=t, stderr="") >>> >>> >> stderr >> >> >>> file.exists(t) >>> >>> >> [1] TRUE >> >> >> Thanks! >> Dan >> >> [[alternative HTML version deleted]] >> >> ______________________________________________ >> R-devel@r-project.org mailing list >> https://stat.ethz.ch/mailman/listinfo/r-devel >> >> > > ______________________________________________________________________ > The information in this email is confidential and inte...{{dropped:11}} ______________________________________________ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel