From ripley at stats.ox.ac.uk  Wed May 12 10:04:05 2004
From: ripley at stats.ox.ac.uk (Prof Brian Ripley)
Date: Wed May 12 10:04:13 2004
Subject: [Rd] stdout == 'Terminal' or 'File' {was 'bad interaction ...'}
In-Reply-To: <16545.53575.897894.285835@gargle.gargle.HOWL>
Message-ID: <Pine.LNX.4.44.0405120854140.16123-100000@gannet.stats>

First, on an R console, stdout() is normally neither a `normal file' nor a 
`user terminal'.  Let alone under an embedded R ... or use under ESS
(where for you, Martin, it is neither).

On vanilla R under Unix-alikes (and Rterm but not otherwise) what stdout
is is a function of the C runtime system.  It's up to the C system if it
tells you what stdout has been redirected to, and if it can tell you
whether it is a terminal, or a pty (as used under some versions of Emacs) 
or a file or a socket ....  The information is at best unreliable.

interactive() is as good a test as we have, and I think if a better test 
is required in the interactive case, the user should be asked.


On Wed, 12 May 2004, Martin Maechler wrote:

> >>>>> "MartinS" == Martin Schlather <schlather@cu.lu>
> >>>>>     on Wed, 12 May 2004 09:15:17 +0100 writes:
> 
>     MartinS> Dear Ben,
> 
>     MartinS> I do not know how to solve the general problem that
>     MartinS> backspaces cause within Sweave, but which are
>     MartinS> needed to implement running counters.
> 
> aha!  now I understand more what you are talking about.
> 
> This is a more interesting problem, in general: It's not quite a
> matter of if(interactive()) that Ben tried, but really you want
> to find out if the stdout() connection you are using is a normal file
> (where you don't need or want a running counter) or a 
> user terminal where Martin Schlather applied the  1^H2^H... ('1' Backspace
> '2' Backspace ..) trick.
> 
> Any ideas what can be done here, using our current  connection
> tools -- or is there the need for something new?
> Interesting topic!
> 
> Martin M?chler
> 
> PS. I know that strictly speaking the subject question is
>  non-sense, since, at least on Unix-alikes, a console is a
>  special file as well, and stdout is always a file.

-- 
Brian D. Ripley,                  ripley@stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595


[Rd] stdout == 'Terminal' or 'File' {was 'bad interaction ...'}
Prof Brian Ripley