repeat { readline() }

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

repeat { readline() }

Henrik Bengtsson-2
Hi.

Using Rterm v2.2.1 on WinXP, is there a way to interrupt a call like

  repeat { readline() }

without killing the Command window?  Ctrl+C is not interrupting the loop:

R : Copyright 2006, The R Foundation for Statistical Computing
Version 2.2.1 Patched (2006-01-01 r36947)
<snip></snip>

 > repeat { readline() }
^C
^C
^C
^C

On Unix it works.  The problem seems to get the interrupt signal to
"occur" outside the readline() call so that "repeat" is interrupted. Doing

repeat { readline(); Sys.sleep(3) }

and it is likely that can generate an interrupt signal outside readline().

It seem like readline()/readLines(n=1) or an underlying method catches
the interrupt signal quietly and just waits for a symbol to come
through.  Try readline() by itself and press Ctrl+C.  Maybe this is a
property of the Windows Command terminal, I don't know, but is it a
wanted feature and are R core aware of it?  Note that, in Rgui it is
possible to interrupting such a loop by pressing ESC.

Cheers

Henrik

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Reply | Threaded
Open this post in threaded view
|

Re: repeat { readline() }

Prof Brian Ripley
Ctrl-Break works: see the rw-FAQ and README.rterm.  (You'll need a return
to see a new prompt.)

It is related to your reading directly from the console, so Ctrl-C is
getting sent to the wrong place, I believe.  (There's a comment from Guido
somewhere in the sources about this, and this seems corroborated by the
fact that Ctrl-C will interrupt under Rterm --ess.)

On Sun, 8 Jan 2006, Henrik Bengtsson wrote:

> Hi.
>
> Using Rterm v2.2.1 on WinXP, is there a way to interrupt a call like
>
>  repeat { readline() }
>
> without killing the Command window?  Ctrl+C is not interrupting the loop:
>
> R : Copyright 2006, The R Foundation for Statistical Computing
> Version 2.2.1 Patched (2006-01-01 r36947)
> <snip></snip>
>
> > repeat { readline() }
> ^C
> ^C
> ^C
> ^C
>
> On Unix it works.  The problem seems to get the interrupt signal to
> "occur" outside the readline() call so that "repeat" is interrupted. Doing
>
> repeat { readline(); Sys.sleep(3) }
>
> and it is likely that can generate an interrupt signal outside readline().
>
> It seem like readline()/readLines(n=1) or an underlying method catches
> the interrupt signal quietly and just waits for a symbol to come
> through.  Try readline() by itself and press Ctrl+C.  Maybe this is a
> property of the Windows Command terminal, I don't know, but is it a
> wanted feature and are R core aware of it?  Note that, in Rgui it is
> possible to interrupting such a loop by pressing ESC.
>
> Cheers
>
> Henrik
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>

--
Brian D. Ripley,                  [hidden email]
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

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Reply | Threaded
Open this post in threaded view
|

Re: repeat { readline() }

hadley wickham
In reply to this post by Henrik Bengtsson-2
On a related note, does anyone know how to exit:

repeat { try( readline() ) }

The try block captures Ctrl-C.

Hadley

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Reply | Threaded
Open this post in threaded view
|

Re: repeat { readline() }

Prof Brian Ripley
In reply to this post by Prof Brian Ripley
On Sun, 8 Jan 2006, Prof Brian Ripley wrote:

> Ctrl-Break works: see the rw-FAQ and README.rterm.  (You'll need a return
> to see a new prompt.)
>
> It is related to your reading directly from the console, so Ctrl-C is
> getting sent to the wrong place, I believe.  (There's a comment from Guido
> somewhere in the sources about this, and this seems corroborated by the
> fact that Ctrl-C will interrupt under Rterm --ess.)

Although the comment is there (in psignal.c), on closer examination the
cause is a change Guido made to getline.c, so Ctrl-C is treated as a
character during keyboard input.  I doubt if that was intentional (0 is
not the default state) and I have changed it for R-devel.\

>
> On Sun, 8 Jan 2006, Henrik Bengtsson wrote:
>
>> Hi.
>>
>> Using Rterm v2.2.1 on WinXP, is there a way to interrupt a call like
>>
>>  repeat { readline() }
>>
>> without killing the Command window?  Ctrl+C is not interrupting the loop:
>>
>> R : Copyright 2006, The R Foundation for Statistical Computing
>> Version 2.2.1 Patched (2006-01-01 r36947)
>> <snip></snip>
>>
>>> repeat { readline() }
>> ^C
>> ^C
>> ^C
>> ^C
>>
>> On Unix it works.  The problem seems to get the interrupt signal to
>> "occur" outside the readline() call so that "repeat" is interrupted. Doing
>>
>> repeat { readline(); Sys.sleep(3) }
>>
>> and it is likely that can generate an interrupt signal outside readline().
>>
>> It seem like readline()/readLines(n=1) or an underlying method catches
>> the interrupt signal quietly and just waits for a symbol to come
>> through.  Try readline() by itself and press Ctrl+C.  Maybe this is a
>> property of the Windows Command terminal, I don't know, but is it a
>> wanted feature and are R core aware of it?  Note that, in Rgui it is
>> possible to interrupting such a loop by pressing ESC.
>>
>> Cheers
>>
>> Henrik
>>
>> ______________________________________________
>> [hidden email] mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>>
>
> --
> Brian D. Ripley,                  [hidden email]
> 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
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>

--
Brian D. Ripley,                  [hidden email]
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

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Reply | Threaded
Open this post in threaded view
|

Re: repeat { readline() }

Henrik Bengtsson-2
Prof Brian Ripley wrote:

> On Sun, 8 Jan 2006, Prof Brian Ripley wrote:
>
>> Ctrl-Break works: see the rw-FAQ and README.rterm.  (You'll need a return
>> to see a new prompt.)
>>
>> It is related to your reading directly from the console, so Ctrl-C is
>> getting sent to the wrong place, I believe.  (There's a comment from
>> Guido
>> somewhere in the sources about this, and this seems corroborated by the
>> fact that Ctrl-C will interrupt under Rterm --ess.)
>
>
> Although the comment is there (in psignal.c), on closer examination the
> cause is a change Guido made to getline.c, so Ctrl-C is treated as a
> character during keyboard input.  I doubt if that was intentional (0 is
> not the default state) and I have changed it for R-devel.\

Thank you very much this.

Henrik

>>
>> On Sun, 8 Jan 2006, Henrik Bengtsson wrote:
>>
>>> Hi.
>>>
>>> Using Rterm v2.2.1 on WinXP, is there a way to interrupt a call like
>>>
>>>  repeat { readline() }
>>>
>>> without killing the Command window?  Ctrl+C is not interrupting the
>>> loop:
>>>
>>> R : Copyright 2006, The R Foundation for Statistical Computing
>>> Version 2.2.1 Patched (2006-01-01 r36947)
>>> <snip></snip>
>>>
>>>> repeat { readline() }
>>>
>>> ^C
>>> ^C
>>> ^C
>>> ^C
>>>
>>> On Unix it works.  The problem seems to get the interrupt signal to
>>> "occur" outside the readline() call so that "repeat" is interrupted.
>>> Doing
>>>
>>> repeat { readline(); Sys.sleep(3) }
>>>
>>> and it is likely that can generate an interrupt signal outside
>>> readline().
>>>
>>> It seem like readline()/readLines(n=1) or an underlying method catches
>>> the interrupt signal quietly and just waits for a symbol to come
>>> through.  Try readline() by itself and press Ctrl+C.  Maybe this is a
>>> property of the Windows Command terminal, I don't know, but is it a
>>> wanted feature and are R core aware of it?  Note that, in Rgui it is
>>> possible to interrupting such a loop by pressing ESC.
>>>
>>> Cheers
>>>
>>> Henrik
>>>
>>> ______________________________________________
>>> [hidden email] mailing list
>>> https://stat.ethz.ch/mailman/listinfo/r-help
>>> PLEASE do read the posting guide!
>>> http://www.R-project.org/posting-guide.html
>>>
>>
>> --
>> Brian D. Ripley,                  [hidden email]
>> 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
>>
>> ______________________________________________
>> [hidden email] mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide!
>> http://www.R-project.org/posting-guide.html
>>
>

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Reply | Threaded
Open this post in threaded view
|

Re: repeat { readline() }

justin bem
In reply to this post by Henrik Bengtsson-2

--- Henrik Bengtsson <[hidden email]> a écrit :

> Hi.
>
> Using Rterm v2.2.1 on WinXP, is there a way to
> interrupt a call like
>
>   repeat { readline() }
>
> without killing the Command window?  Ctrl+C is not
> interrupting the loop:

To interupt the loop add and condition for a break
like this :
if () break



>
> R : Copyright 2006, The R Foundation for Statistical
> Computing
> Version 2.2.1 Patched (2006-01-01 r36947)
> <snip></snip>
>
>  > repeat { readline() }
> ^C
> ^C
> ^C
> ^C
>
> On Unix it works.  The problem seems to get the
> interrupt signal to
> "occur" outside the readline() call so that "repeat"
> is interrupted. Doing
>
> repeat { readline(); Sys.sleep(3) }
>
> and it is likely that can generate an interrupt
> signal outside readline().
>
> It seem like readline()/readLines(n=1) or an
> underlying method catches
> the interrupt signal quietly and just waits for a
> symbol to come
> through.  Try readline() by itself and press Ctrl+C.
>  Maybe this is a
> property of the Windows Command terminal, I don't
> know, but is it a
> wanted feature and are R core aware of it?  Note
> that, in Rgui it is
> possible to interrupting such a loop by pressing
> ESC.
>
> Cheers
>
> Henrik
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
> http://www.R-project.org/posting-guide.html
>

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Reply | Threaded
Open this post in threaded view
|

Re: repeat { readline() }

Luke Tierney
In reply to this post by hadley wickham
Use tryCatch; try behaves the way it does with respect to interrupts
for historical compatibility.

luke

On Sun, 8 Jan 2006, hadley wickham wrote:

> On a related note, does anyone know how to exit:
>
> repeat { try( readline() ) }
>
> The try block captures Ctrl-C.
>
> Hadley
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>

--
Luke Tierney
Chair, Statistics and Actuarial Science
Ralph E. Wareham Professor of Mathematical Sciences
University of Iowa                  Phone:             319-335-3386
Department of Statistics and        Fax:               319-335-3017
    Actuarial Science
241 Schaeffer Hall                  email:      [hidden email]
Iowa City, IA 52242                 WWW:  http://www.stat.uiowa.edu

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html