HDoran@air.org
2005-Jul-08 13:36 UTC
[Rd] Sweave resource leak: leftover temp files (PR#7999)
This is great. Thank you for your help, but let me make sure I fully understand. Here is the looping file I use to subset the data frame, create a tex file, and Sweave it. This results in N number of tex files where N is equal to the number of rows in the data frame. list <- unique(wide$stuid) master = "master.tex" for (i in list){ tmp1 <- subset(wide, stuid==i) tmp2 <- paste(i, "tex", sep=".") Sweave("fam_template.Rnw", output=tmp2) file.append("fam_master.tex", tmp2) } If I follow correctly, I would need to place these commands inside the loop as follows: list <- unique(wide$stuid) master = "master.tex" for (i in list){ tmp1 <- subset(wide, stuid==i) tmp2 <- paste(i, "tex", sep=".") keep <- list.files(tempdir(), full=TRUE) # keep previous temp files Sweave("fam_template.Rnw", output=tmp2) file.append("fam_master.tex", tmp2) temps <- list.files(tempdir(), full=TRUE) unlink(temps[!(temps %in% keep)]) # delete the newly created ones } Thank you for taking the time to look at this. Harold -----Original Message----- From: Duncan Murdoch [mailto:murdoch at stats.uwo.ca] Sent: Friday, July 08, 2005 9:28 AM To: Duncan Murdoch Cc: Doran, Harold; r-bugs at r-project.org; Uwe Ligges; Sean O'Riordain Subject: Sweave resource leak: leftover temp files 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
Duncan Murdoch
2005-Jul-08 14:09 UTC
[Rd] Sweave resource leak: leftover temp files (PR#7999)
One additional note: followups should only go to R-bugs if they have the bug number on them (like this message does). Otherwise you end up generating a separate bug report (PR#7999 was created in your reply to my submission of PR#7998). Usually it's best just to cc R-devel, unless you really have additional information to add to the bug report. We're planning (or in the process of?) changing the bug reporting system, so this is only a temporary inconvenience. Duncan Murdoch On 7/8/2005 9:36 AM, HDoran at air.org wrote:> This is great. Thank you for your help, but let me make sure I fully > understand. Here is the looping file I use to subset the data frame, > create a tex file, and Sweave it. This results in N number of tex files > where N is equal to the number of rows in the data frame. > > list <- unique(wide$stuid) > master = "master.tex" > for (i in list){ > tmp1 <- subset(wide, stuid==i) > tmp2 <- paste(i, "tex", sep=".") > Sweave("fam_template.Rnw", output=tmp2) > file.append("fam_master.tex", tmp2) > } > > If I follow correctly, I would need to place these commands inside the > loop as follows: > > list <- unique(wide$stuid) > master = "master.tex" > for (i in list){ > tmp1 <- subset(wide, stuid==i) > tmp2 <- paste(i, "tex", sep=".") > keep <- list.files(tempdir(), full=TRUE) # keep previous temp > files > Sweave("fam_template.Rnw", output=tmp2) > file.append("fam_master.tex", tmp2) > temps <- list.files(tempdir(), full=TRUE) unlink(temps[!(temps %in% > keep)]) # delete the newly created ones > } > > > Thank you for taking the time to look at this. > > Harold > > -----Original Message----- > From: Duncan Murdoch [mailto:murdoch at stats.uwo.ca] > Sent: Friday, July 08, 2005 9:28 AM > To: Duncan Murdoch > Cc: Doran, Harold; r-bugs at r-project.org; Uwe Ligges; Sean O'Riordain > Subject: Sweave resource leak: leftover temp files > > 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 > > ______________________________________________ > R-devel at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-devel
Doran, Harold
2005-Jul-08 15:25 UTC
[Rd] Sweave resource leak: leftover temp files (PR#7999)
Duncan and d-level Your proposed solution works well and seems to resolve the issue. I previously noted to you that it seemed to run slower, but this is not true. I restarted R and it is equally as fast. Thank you for your attention to this matter. -Harold -----Original Message----- From: Duncan Murdoch [mailto:murdoch at stats.uwo.ca] Sent: Friday, July 08, 2005 10:10 AM To: Doran, Harold Cc: r-devel at stat.math.ethz.ch Subject: Re: [Rd] Sweave resource leak: leftover temp files (PR#7999) One additional note: followups should only go to R-bugs if they have the bug number on them (like this message does). Otherwise you end up generating a separate bug report (PR#7999 was created in your reply to my submission of PR#7998). Usually it's best just to cc R-devel, unless you really have additional information to add to the bug report. We're planning (or in the process of?) changing the bug reporting system, so this is only a temporary inconvenience. Duncan Murdoch On 7/8/2005 9:36 AM, HDoran at air.org wrote:> This is great. Thank you for your help, but let me make sure I fully > understand. Here is the looping file I use to subset the data frame, > create a tex file, and Sweave it. This results in N number of tex > files where N is equal to the number of rows in the data frame. > > list <- unique(wide$stuid) > master = "master.tex" > for (i in list){ > tmp1 <- subset(wide, stuid==i) > tmp2 <- paste(i, "tex", sep=".") > Sweave("fam_template.Rnw", output=tmp2) > file.append("fam_master.tex", tmp2) } > > If I follow correctly, I would need to place these commands inside the> loop as follows: > > list <- unique(wide$stuid) > master = "master.tex" > for (i in list){ > tmp1 <- subset(wide, stuid==i) > tmp2 <- paste(i, "tex", sep=".") > keep <- list.files(tempdir(), full=TRUE) # keep previous temp > files > Sweave("fam_template.Rnw", output=tmp2) > file.append("fam_master.tex", tmp2) > temps <- list.files(tempdir(), full=TRUE) unlink(temps[!(temps > %in% > keep)]) # delete the newly created ones } > > > Thank you for taking the time to look at this. > > Harold > > -----Original Message----- > From: Duncan Murdoch [mailto:murdoch at stats.uwo.ca] > Sent: Friday, July 08, 2005 9:28 AM > To: Duncan Murdoch > Cc: Doran, Harold; r-bugs at r-project.org; Uwe Ligges; Sean O'Riordain > Subject: Sweave resource leak: leftover temp files > > 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 > > ______________________________________________ > R-devel at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-devel