[Rd] Sweave resource leak: leftover temp files (PR#7998)

murdoch@stats.uwo.ca murdoch at stats.uwo.ca
Fri Jul 8 15:26:00 CEST 2005


Harold, I've taken a closer look at your example and I'd call this an 
Sweave bug.  It creates tempfiles each time you run it, and doesn't 
delete them at the end.  For example:

 > list.files(tempdir())
character(0)
 > testfile <- system.file("Sweave", "Sweave-test-1.Rnw", package = "utils")
 > Sweave(testfile, out="junk.tex")
Writing to file junk.tex
Processing code chunks ...
  1 : print term verbatim
  2 : term hide
  3 : echo print term verbatim
  4 : term verbatim
  5 : echo term verbatim
  6 : echo term verbatim eps pdf
  7 : echo term verbatim eps pdf

You can now run LaTeX on 'junk.tex'
 > list.files(tempdir())
  [1] "Rf10523" "Rf13872" "Rf17129" "Rf2055"  "Rf2203"  "Rf2403"  "Rf27095"
  [8] "Rf2892"  "Rf31415" "Rf5290"  "Rf6251"  "Rf6482"  "Rf7055"  "Rf724"
 > Sweave(testfile, out="C:/temp/junk.tex")
Writing to file C:/temp/junk.tex
Processing code chunks ...
  1 : print term verbatim
  2 : term hide
  3 : echo print term verbatim
  4 : term verbatim
  5 : echo term verbatim
  6 : echo term verbatim eps pdf
  7 : echo term verbatim eps pdf

You can now run LaTeX on 'C:/temp/junk.tex'
 > list.files(tempdir())
  [1] "Rf10523" "Rf12679" "Rf1311"  "Rf13484" "Rf13872" "Rf17129" "Rf17288"
  [8] "Rf2055"  "Rf21774" "Rf2203"  "Rf23417" "Rf2403"  "Rf27095" "Rf2892"
[15] "Rf29444" "Rf31128" "Rf31415" "Rf32520" "Rf3338"  "Rf5290"  "Rf5551"
[22] "Rf6251"  "Rf6482"  "Rf7055"  "Rf724"   "Rf7543"  "Rf758"   "Rf7673"
 > unlink(list.files(tempdir(),full=T))
 > list.files(tempdir())
character(0)

Harold:  a workaround for this would be to wrap your Sweave call in 
something like this:

keep <- list.files(tempdir(), full=TRUE)  # keep previous temp files

... Call Sweave here ...

temps <- list.files(tempdir(), full=TRUE)
unlink(temps[!(temps %in% keep)])  # delete the newly created ones



More information about the R-devel mailing list