[R] Rgui maintains open file handles after Sweave error

Henrik Bengtsson hb at biostat.ucsf.edu
Wed Apr 4 21:45:20 CEST 2012


See ?closeAllConnections

Suggestion to the maintainer of Sweave: "atomify" the figure
generation, e.g. use { pdf(); on.exit(dev.off()); {...}; } or similar,
instead of { pdf(); {...}; dev.off(); } possibly by leaving a copy of
the fault figure file for troubleshooting.

/Henrik

On Wed, Apr 4, 2012 at 12:25 PM, Alexander Shenkin <ashenkin at ufl.edu> wrote:
> Hello Folks,
>
> When I run the document below through sweave, rgui.exe/rsession.exe
> leaves a file handle open to the sweave-001.pdf graphic (as verified by
> process explorer).  Pdflatex.exe then crashes (with a Permission Denied
> error) because the graphic file is locked.
>
> This only seems to happen when there is an error in the sweave document.
>  When there are no errors, no file handles are left open.  However, once
> a file handle is stuck open, I can find no other way of closing it save
> for quitting out of R.
>
> Any help would be greatly appreciated!  It would be nice to be able to
> write flawless sweave every time, but flawed as I am, I am having to
> restart R continuously.
>
> Thanks,
> Allie
>
>
> OS: Windows 7 Pro x64 SP1
>
>
>> sessionInfo()
> R version 2.14.2 (2012-02-29)
> Platform: i386-pc-mingw32/i386 (32-bit)
>
>
> test.Rnw:
>
>    \documentclass{article}
>    \title {file handle test}
>    \author{test author}
>    \usepackage{Sweave}
>    \begin {document}
>    \maketitle
>
>    \SweaveOpts{prefix.string=sweave}
>
>    \begin{figure}
>    \begin{center}
>
>    <<fig=TRUE, echo=FALSE>>=
>        df = data.frame(a=rnorm(100), b=rnorm(100), group = c("g1",
> "g2", "g3", "g4"))
>        plot(df$a, df$y, foo)
>    @
>
>    \caption{test figure one}
>    \label{fig:one}
>    \end{center}
>    \end{figure}
>    \end{document}
>
>
>
> Sweave command run:
>
>    Sweave("test.Rnw", syntax="SweaveSyntaxNoweb")
>
>
>
> Sweave.sty:
>
>    \NeedsTeXFormat{LaTeX2e}
>    \ProvidesPackage{Sweave}{}
>
>    \RequirePackage{ifthen}
>    \newboolean{Sweave at gin}
>    \setboolean{Sweave at gin}{true}
>    \newboolean{Sweave at ae}
>    \setboolean{Sweave at ae}{true}
>
>    \DeclareOption{nogin}{\setboolean{Sweave at gin}{false}}
>    \DeclareOption{noae}{\setboolean{Sweave at ae}{false}}
>    \ProcessOptions
>
>    \RequirePackage{graphicx,fancyvrb}
>    \IfFileExists{upquote.sty}{\RequirePackage{upquote}}{}
>
>    \ifthenelse{\boolean{Sweave at gin}}{\setkeys{Gin}{width=0.8\textwidth}}{}%
>    \ifthenelse{\boolean{Sweave at ae}}{%
>      \RequirePackage[T1]{fontenc}
>      \RequirePackage{ae}
>    }{}%
>
>    \DefineVerbatimEnvironment{Sinput}{Verbatim}{fontshape=sl}
>    \DefineVerbatimEnvironment{Soutput}{Verbatim}{}
>    \DefineVerbatimEnvironment{Scode}{Verbatim}{fontshape=sl}
>
>    \newenvironment{Schunk}{}{}
>
>    \newcommand{\Sconcordance}[1]{%
>      \ifx\pdfoutput\undefined%
>      \csname newcount\endcsname\pdfoutput\fi%
>      \ifcase\pdfoutput\special{#1}%
>      \else\immediate\pdfobj{#1}\fi}
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list