[R] Rgui maintains open file handles after Sweave error
Alexander Shenkin
ashenkin at ufl.edu
Thu Apr 5 19:26:38 CEST 2012
Yep, I'm using RStudio, and have used Tinn-R in the past. RStudio does
start a new R session when processing a sweave document via the RStudio
GUI. In my case, this presented a problem for the reasons I stated
before (i.e. that I need to run sweave in the main environment, not a
new one). Hence, I'm running Sweave from the command line, and
processing the tex doc via TeXworks (from MiKTeX). I sent the RStudio
team a feature request to add an option to be able to run Sweave in the
main environment (perhaps while maintaining the default of running it in
a separate environment).
Allie
On 4/5/2012 12:12 PM, Yihui Xie wrote:
> In terms of editors, I think RStudio is pretty good
> (http://www.rstudio.org/download/preview). Or LyX
> (http://yihui.name/knitr/demo/lyx/), or TeXmaker, WinEdit
> (http://yihui.name/knitr/demo/editors/)... All of them start a new R
> session when weaving the document, and all support one-click
> compilation. In all, anything but Windows Notepad.
>
> Regards,
> Yihui
> --
> Yihui Xie <xieyihui at gmail.com>
> Phone: 515-294-2465 Web: http://yihui.name
> Department of Statistics, Iowa State University
> 2215 Snedecor Hall, Ames, IA
>
>
>
> On Thu, Apr 5, 2012 at 11:22 AM, Duncan Murdoch
> <murdoch.duncan at gmail.com> 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.
>>
>>
>> ______________________________________________
>> 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