From mdsumner at gmail.com  Mon Oct 28 23:24:57 2013
From: mdsumner at gmail.com (Michael Sumner)
Date: Tue, 29 Oct 2013 09:24:57 +1100
Subject: [Rd] interrupting Sweave leaves open sink connection
In-Reply-To: <5267B795.5040906@gmail.com>
References: <CAAcGz9_eB7nUgrDuAroEfP6bwg-mMjXgqMeokVzRXGj0y_jDQQ@mail.gmail.com>
	<52673830.8090405@gmail.com> <5267B795.5040906@gmail.com>
Message-ID: <CAAcGz995bGrfXr+6PNeS5Ev2fN4P3OPzizwgzRyj76Pgs35=DQ@mail.gmail.com>

Thanks very much, confirmed in Windows in R-patched (r64110) and
R-devel (r64116).

Cheers, Mike.

On Wed, Oct 23, 2013 at 10:48 PM, Duncan Murdoch
<murdoch.duncan at gmail.com> wrote:
> On 13-10-22 10:45 PM, Duncan Murdoch wrote:
>>
>> On 13-10-22 9:45 PM, Michael Sumner wrote:
>>>
>>> Hello, if I interrupt Sweave while it's processing a file it seemingly
>>> leaves an open sink connection that hides printed output.
>>>
>>> Can this be changed to reset the sink on exit?  I've been baffled by
>>> this for years.
>>>
>>> This is seen in Windows (R Under development (unstable) (2013-10-20
>>> r64082))  and an older Linux (R version 3.0.0 (2013-04-03)).
>>>
>>> Run the code below in two parts with a manual interrupt to 1) to see it.
>>
>>
>> That's a bug in the Rweave driver.  It runs the code in try() so that it
>> can catch errors and undo the sink, but try() doesn't catch user
>> interrupts, so it never gets undone.
>>
>> Shouldn't be too hard to fix...
>
>
> It should now be fixed in R-devel and R-patched.
>
> Likely the reason this went unfixed for so long is that the more common way
> to use Sweave is in a separate R session.  If you run it in the current R
> session, the results aren't necessarily reproducible, because they may
> depend on whatever variables you have in your workspace.  It's better to run
> it on its own.  One way is to use the command line version
>
> R CMD Sweave ...
>
> but it can also be done by piping specific commands into an R session. I do
> it that way, because it lets me run some project management code, and lets
> me patch the Synctex information so it points to the .Rnw file.
>
> Duncan Murdoch
>
>
>>
>> Duncan Murdoch
>>
>>>
>>> Cheers, MIke.
>>>
>>> ## 1)
>>>
>>> ## this code creates a temporary file to run Sweave
>>>
>>> ## interrupt this code before Sweave() finishes
>>>
>>> txt <-  c("\\documentclass[a4paper]{article}", "\\title{Sweave bail
>>> out}",
>>> "\\author{M. Sumner}", "\\begin{document}", "\\maketitle", "",
>>> "Run a loop and bail out when Sweave()ing.", "", "<<>>=",
>>> "for (i in seq_len(1e6)) {", "    if (i %% 1000 == 0)
>>> print(sprintf(\"%i\", i))",
>>> "    Sys.sleep(0.5)", "}", "@", "", "\\end{document}")
>>>
>>> f <- tempfile()
>>> writeLines(txt, f)
>>>
>>> Sweave(f)
>>>
>>> ## 2)
>>> ## now no printed output is seen
>>> print(1)
>>> ##
>>>
>>> sink(NULL)
>>>
>>> ## now it's back
>>> print(1)
>>> ## [1] 1
>>>
>>> ## tidy up
>>> ## unlink(f)
>>>
>>>
>>>
>>>
>>>
>>
>



-- 
Michael Sumner
Hobart, Australia
e-mail: mdsumner at gmail.com



[Rd] interrupting Sweave leaves open sink connection
Michael Sumner