[R] Rgui maintains open file handles after Sweave error

Alexander Shenkin ashenkin at ufl.edu
Thu Apr 5 18:31:53 CEST 2012


Thanks for the nice ideas, Duncan.  I think that would work nicely in
most cases.  The major issue with that workflow in my case is that the
scripts to set up my workspace take around a half-hour to run (I really
wish CUDA was working with my setup!), so running R each time in that
case is time-consuming.

Perhaps I should be working more with intermediate files, or perhaps
writing the workspace out to an .Rdata file and reading that in the
sweave document instead of running the entire data-prep script.

Thanks,
Allie

On 4/5/2012 11:22 AM, Duncan Murdoch wrote:
> On 04/04/2012 3:25 PM, Alexander Shenkin 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.
> 
> I'd suggest a different workflow, in which you run a new copy of R every
> time you want to Sweave a document.  The files will be closed when that
> copy dies, and the results are less likely to be affected by the current
> state of your workspace (assuming you don't load an old workspace in the
> new copy).
> 
> For example, when I'm working on a Sweave document, I spend my time in
> my text editor, and get it to run R to process the file whenever I want
> to see what the output looks like.
> 
> The only real disadvantages to this approach that I can think of are
> that you need to figure out how to tell your text editor to run R (and
> that might be hard if you're using a poor editor like Windows Notebook,
> but is usually easy), and it will run a tiny bit slower because you need
> to start up R every time.
> 
> Duncan Murdoch
> 
>> 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