cat with backspace and newline characters

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
21 messages Options
12
Reply | Threaded
Open this post in threaded view
|

cat with backspace and newline characters

Renaud Gaujoux
Hi,

when mixing newline and backspace characters I get the following output
(see below). In the second call, the backspace character is simply not
applied. Is this normal behaviour?
Thank you.

> cat("abc\b")
ab> cat("abc\b\n")
abc
>

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: cat with backspace and newline characters

Renaud Gaujoux
I don't know what the normal behaviour is. I was expecting the remaining of
the line to be wiped out, but you must be right: the character 'c' is
already printed, the cursor moves back one position and go to the next
line, leaving the 'c' in place.
But what about this one:

> cat("abc\b\b\b")
> c

Here, I end up with the cursor being on the 'c', i.e. if I type something
it erase the 'c'.
It is strange that the 'c' appears _after_ the console prompt, isn't it?

Renaud




On 1 November 2013 13:41, Sean O'Riordain <[hidden email]> wrote:

> Hi Renaud,
>
> Are you sure it's not applied? is \b a backspace i.e. just move the
> cursor back one space, or is it a delete the character to the left of
> the cursor?
>
> Kind regards,
> Sean
>
>
> On 1 November 2013 11:06, Renaud Gaujoux <[hidden email]>
> wrote:
> > Hi,
> >
> > when mixing newline and backspace characters I get the following output
> > (see below). In the second call, the backspace character is simply not
> > applied. Is this normal behaviour?
> > Thank you.
> >
> >> cat("abc\b")
> > ab> cat("abc\b\n")
> > abc
> >>
> >
> >         [[alternative HTML version deleted]]
> >
> > ______________________________________________
> > [hidden email] mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-devel
>
>

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: cat with backspace and newline characters

Rui Barradas
In reply to this post by Renaud Gaujoux
Hello,

Can't reproduce it, there must be something with your console. I get

 > cat("abc\b")
ab> cat("abc\b\n")
ab
 >


Hope this helps,

Rui Barradas

Em 01-11-2013 11:06, Renaud Gaujoux escreveu:

> Hi,
>
> when mixing newline and backspace characters I get the following output
> (see below). In the second call, the backspace character is simply not
> applied. Is this normal behaviour?
> Thank you.
>
>> cat("abc\b")
> ab> cat("abc\b\n")
> abc
>>
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: cat with backspace and newline characters

Renaud Gaujoux
In reply to this post by Renaud Gaujoux
Maybe it's a Linux problem:

> cat("abc\b")
ab> cat("abc\b\n")
abc
> sessionInfo()
R version 3.0.2 (2013-09-25)
Platform: x86_64-pc-linux-gnu (64-bit)

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C
 [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8
 [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8
 [7] LC_PAPER=en_US.UTF-8       LC_NAME=C
 [9] LC_ADDRESS=C               LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base
>
> Sys.info()
                                     sysname
                                     "Linux"
                                     release
                         "3.11.0-12-generic"
                                     version
"#19-Ubuntu SMP Wed Oct 9 16:20:46 UTC 2013"
                                    nodename
                                     "XXXXX"
                                     machine
                                    "x86_64"
                                       login
                                    "XXXXX"
                                        user
                                    "XXXXX"
                              effective_user
                                    "XXXXX"
>




On 1 November 2013 19:54, Dennis Murphy <[hidden email]> wrote:

> I can't reproduce the error, either:
>
> > cat("abc\b")
> ab> cat("abc\b\n")
> ab
> >
> > sessionInfo()
> R version 3.0.2 (2013-09-25)
> Platform: x86_64-w64-mingw32/x64 (64-bit)
>
> locale:
> [1] LC_COLLATE=English_United States.1252
> [2] LC_CTYPE=English_United States.1252
> [3] LC_MONETARY=English_United States.1252
> [4] LC_NUMERIC=C
> [5] LC_TIME=English_United States.1252
>
> <package info snipped for brevity>
>
> Dennis
>

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: cat with backspace and newline characters

Kenn Konstabel
I just tried it on ubuntu but within RStudio:

> cat("abc\b")
ab
> cat("abc\b\n")
ab
> sessionInfo()
R version 3.0.2 (2013-09-25)
Platform: x86_64-pc-linux-gnu (64-bit)

locale:
 [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C         LC_TIME=C
LC_COLLATE=C
 [5] LC_MONETARY=C        LC_MESSAGES=C        LC_PAPER=C
LC_NAME=C
 [9] LC_ADDRESS=C         LC_TELEPHONE=C       LC_MEASUREMENT=C
LC_IDENTIFICATION=C

--------

On the same machine but running R in the terminal (tried with GNOME
terminal, Konsole, and xterm with no difference )

> cat("abc\b")
ab> cat("abc\b\n")
abc
> sessionInfo()
R version 3.0.2 (2013-09-25)
Platform: x86_64-pc-linux-gnu (64-bit)

locale:
 [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C         LC_TIME=C
 [4] LC_COLLATE=C         LC_MONETARY=C        LC_MESSAGES=C
 [7] LC_PAPER=C           LC_NAME=C            LC_ADDRESS=C
[10] LC_TELEPHONE=C       LC_MEASUREMENT=C     LC_IDENTIFICATION=C

---------


But then again ...

cat("abc\b \n")

... seems to work the same way everywhere. It looks like the logic in a
unix terminal is that \b moves the cursor backwards but does not replace or
delete anything that was there before.

Regards,
Kenn





On Tue, Nov 5, 2013 at 12:53 PM, Renaud Gaujoux <
[hidden email]> wrote:

> Maybe it's a Linux problem:
>
> > cat("abc\b")
> ab> cat("abc\b\n")
> abc
> > sessionInfo()
> R version 3.0.2 (2013-09-25)
> Platform: x86_64-pc-linux-gnu (64-bit)
>
> locale:
>  [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C
>  [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8
>  [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8
>  [7] LC_PAPER=en_US.UTF-8       LC_NAME=C
>  [9] LC_ADDRESS=C               LC_TELEPHONE=C
> [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
>
> attached base packages:
> [1] stats     graphics  grDevices utils     datasets  methods   base
> >
> > Sys.info()
>                                      sysname
>                                      "Linux"
>                                      release
>                          "3.11.0-12-generic"
>                                      version
> "#19-Ubuntu SMP Wed Oct 9 16:20:46 UTC 2013"
>                                     nodename
>                                      "XXXXX"
>                                      machine
>                                     "x86_64"
>                                        login
>                                     "XXXXX"
>                                         user
>                                     "XXXXX"
>                               effective_user
>                                     "XXXXX"
> >
>
>
>
>
> On 1 November 2013 19:54, Dennis Murphy <[hidden email]> wrote:
>
> > I can't reproduce the error, either:
> >
> > > cat("abc\b")
> > ab> cat("abc\b\n")
> > ab
> > >
> > > sessionInfo()
> > R version 3.0.2 (2013-09-25)
> > Platform: x86_64-w64-mingw32/x64 (64-bit)
> >
> > locale:
> > [1] LC_COLLATE=English_United States.1252
> > [2] LC_CTYPE=English_United States.1252
> > [3] LC_MONETARY=English_United States.1252
> > [4] LC_NUMERIC=C
> > [5] LC_TIME=English_United States.1252
> >
> > <package info snipped for brevity>
> >
> > Dennis
> >
>
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: cat with backspace and newline characters

Prof Brian Ripley
In reply to this post by Renaud Gaujoux
It is user lack-of-understanding: there is no error here.  R outputs

a
b
c
backspace
newline

How the terminal displays that is up to the terminal, which was
unstated.  (Capture the output and look at it in a hex editor.)

For

a
b
c
backspace

a normal terminal will output the prompt and overwrite 'c'.

On 05/11/2013 10:53, Renaud Gaujoux wrote:

> Maybe it's a Linux problem:
>
>> cat("abc\b")
> ab> cat("abc\b\n")
> abc
>> sessionInfo()
> R version 3.0.2 (2013-09-25)
> Platform: x86_64-pc-linux-gnu (64-bit)
>
> locale:
>   [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C
>   [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8
>   [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8
>   [7] LC_PAPER=en_US.UTF-8       LC_NAME=C
>   [9] LC_ADDRESS=C               LC_TELEPHONE=C
> [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
>
> attached base packages:
> [1] stats     graphics  grDevices utils     datasets  methods   base
>>
>> Sys.info()
>                                       sysname
>                                       "Linux"
>                                       release
>                           "3.11.0-12-generic"
>                                       version
> "#19-Ubuntu SMP Wed Oct 9 16:20:46 UTC 2013"
>                                      nodename
>                                       "XXXXX"
>                                       machine
>                                      "x86_64"
>                                         login
>                                      "XXXXX"
>                                          user
>                                      "XXXXX"
>                                effective_user
>                                      "XXXXX"
>>
>
>
>
>
> On 1 November 2013 19:54, Dennis Murphy <[hidden email]> wrote:
>
>> I can't reproduce the error, either:
>>
>>> cat("abc\b")
>> ab> cat("abc\b\n")
>> ab
>>>
>>> sessionInfo()
>> R version 3.0.2 (2013-09-25)
>> Platform: x86_64-w64-mingw32/x64 (64-bit)
>>
>> locale:
>> [1] LC_COLLATE=English_United States.1252
>> [2] LC_CTYPE=English_United States.1252
>> [3] LC_MONETARY=English_United States.1252
>> [4] LC_NUMERIC=C
>> [5] LC_TIME=English_United States.1252
>>
>> <package info snipped for brevity>
>>
>> Dennis
>>
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>


--
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-devel
Reply | Threaded
Open this post in threaded view
|

Re: cat with backspace and newline characters

Martin Maechler
In reply to this post by Kenn Konstabel
>>>>> Kenn Konstabel <[hidden email]>
>>>>>     on Tue, 5 Nov 2013 13:25:20 +0200 writes:

    > I just tried it on ubuntu but within RStudio:
    >> cat("abc\b")
    > ab
    >> cat("abc\b\n")
    > ab
    >> sessionInfo()

which --- as you allude to below --- shows that  RStudio  has changed R
in so far that it adds a '\n'  even when R, i.e.  cat()  does not.

I can understand that the RStudio programmers want to protect
their users (*) from getting funny looking output,
but I still don't like the fact that R inside RStudio is tweaked
to behave differently from regular R.

Martin Maechler, R Core Team & ETH Zurich

--
(*) or their software from malfunctioning when the console "looks ugly"

    > R version 3.0.2 (2013-09-25) Platform: x86_64-pc-linux-gnu
    > (64-bit)

    > locale: [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C LC_TIME=C
    > LC_COLLATE=C [5] LC_MONETARY=C LC_MESSAGES=C LC_PAPER=C
    > LC_NAME=C [9] LC_ADDRESS=C LC_TELEPHONE=C LC_MEASUREMENT=C
    > LC_IDENTIFICATION=C

    > --------

    > On the same machine but running R in the terminal (tried
    > with GNOME terminal, Konsole, and xterm with no difference
    > )

    >> cat("abc\b")
    ab> cat("abc\b\n")
    > abc
    >> sessionInfo()
    > R version 3.0.2 (2013-09-25) Platform: x86_64-pc-linux-gnu
    > (64-bit)

    > locale: [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C LC_TIME=C
    > [4] LC_COLLATE=C LC_MONETARY=C LC_MESSAGES=C [7]
    > LC_PAPER=C LC_NAME=C LC_ADDRESS=C [10] LC_TELEPHONE=C
    > LC_MEASUREMENT=C LC_IDENTIFICATION=C

    > ---------


    > But then again ...

    > cat("abc\b \n")

    > ... seems to work the same way everywhere. It looks like
    > the logic in a unix terminal is that \b moves the cursor
    > backwards but does not replace or delete anything that was
    > there before.

    > Regards, Kenn





    > On Tue, Nov 5, 2013 at 12:53 PM, Renaud Gaujoux <
    > [hidden email]> wrote:

    >> Maybe it's a Linux problem:
    >>
    >> > cat("abc\b")
    ab> cat("abc\b\n")
    >> abc > sessionInfo() R version 3.0.2 (2013-09-25)
    >> Platform: x86_64-pc-linux-gnu (64-bit)
    >>
    >> locale: [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C [3]
    >> LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8 [5]
    >> LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8 [7]
    >> LC_PAPER=en_US.UTF-8 LC_NAME=C [9] LC_ADDRESS=C
    >> LC_TELEPHONE=C [11] LC_MEASUREMENT=en_US.UTF-8
    >> LC_IDENTIFICATION=C
    >>
    >> attached base packages: [1] stats graphics grDevices
    >> utils datasets methods base
    >> >
    >> > Sys.info() sysname "Linux" release "3.11.0-12-generic"
    >> version "#19-Ubuntu SMP Wed Oct 9 16:20:46 UTC 2013"
    >> nodename "XXXXX" machine "x86_64" login "XXXXX" user
    >> "XXXXX" effective_user "XXXXX"
    >> >
    >>
    >>
    >>
    >>
    >> On 1 November 2013 19:54, Dennis Murphy
    >> <[hidden email]> wrote:
    >>
    >> > I can't reproduce the error, either:
    >> >
    >> > > cat("abc\b") > ab> cat("abc\b\n") > ab
    >> > >
    >> > > sessionInfo() > R version 3.0.2 (2013-09-25) >
    >> Platform: x86_64-w64-mingw32/x64 (64-bit)
    >> >
    >> > locale: > [1] LC_COLLATE=English_United States.1252 >
    >> [2] LC_CTYPE=English_United States.1252 > [3]
    >> LC_MONETARY=English_United States.1252 > [4] LC_NUMERIC=C
    >> > [5] LC_TIME=English_United States.1252
    >> >
    >> > <package info snipped for brevity>
    >> >
    >> > Dennis
    >> >
    >>
    >> [[alternative HTML version deleted]]
    >>
    >> ______________________________________________
    >> [hidden email] mailing list
    >> https://stat.ethz.ch/mailman/listinfo/r-devel
    >>

    > [[alternative HTML version deleted]]

    > ______________________________________________
    > [hidden email] mailing list
    > https://stat.ethz.ch/mailman/listinfo/r-devel

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: cat with backspace and newline characters

braverock
On 11/05/2013 07:22 AM, Martin Maechler wrote:
> which --- as you allude to below --- shows that  RStudio  has changed R
> in so far that it adds a '\n'  even when R, i.e.  cat()  does not.
>
> I can understand that the RStudio programmers want to protect
> their users (*) from getting funny looking output,
> but I still don't like the fact that R inside RStudio is tweaked
> to behave differently from regular R.

No, it just suggests exactly what Prof. Ripley alluded to...

... the output of cat() will be dependent on the display terminal.

RStudio doesn't include R at all, and in fact makes use of the/any R
binary installed via other processes.  It is not 'tweaked'.

It *does* include a 'terminal' to display the interactions with the R
console.

Regards,

Brian

--
Brian G. Peterson
http://braverock.com/brian/
Ph: 773-459-4973
IM: bgpbraverock

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: cat with backspace and newline characters

Renaud Gaujoux
In reply to this post by Prof Brian Ripley
Thanks for the clarification. This appears to be a terminal behaviour issue.

It is user lack-of-understanding: there is no error here.
>

I believe lack of understanding is probably amongst the top reasons why
users post to the list and get happily enlightened.
I don't think I said there was an error though, but only asked if this was
normal behaviour, and apparently many standard Linux terminals get it
wrong. This looks a bit sad for a very terminal-driven OS.

Renaud

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: cat with backspace and newline characters

Martin Maechler
In reply to this post by braverock
>>>>> Brian G Peterson <[hidden email]>
>>>>>     on Tue, 5 Nov 2013 07:30:14 -0600 writes:

    > On 11/05/2013 07:22 AM, Martin Maechler wrote:
    >> which --- as you allude to below --- shows that RStudio
    >> has changed R in so far that it adds a '\n' even when R,
    >> i.e.  cat() does not.
    >>
    >> I can understand that the RStudio programmers want to
    >> protect their users (*) from getting funny looking
    >> output, but I still don't like the fact that R inside
    >> RStudio is tweaked to behave differently from regular R.

    > No, it just suggests exactly what Prof. Ripley alluded
    > to...

    > ... the output of cat() will be dependent on the display
    > terminal.

    > RStudio doesn't include R at all, and in fact makes use of
    > the/any R binary installed via other processes.  It is not
    > 'tweaked'.

    > It *does* include a 'terminal' to display the interactions
    > with the R console.

Well I know that (it does not modify R),
but I'd say that the above is just another way to say what I said:
RStudio tweaks R's output. I agree that this is much much less
problematic than changing R objects, but I'd claim that
where as the interpretation of  \b  depends on the
terminal/console (and so it is quite rarely used),
the functioning of  \n  should not depend on the platform.
RStudio users may conclude that it is a good idea to use things like
        cat("pi:", pi)
whereas they really should use something like
        cat("pi:", pi, "\n)

Martin

    > Regards,
    > Brian

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: cat with backspace and newline characters

Philippe Grosjean
In reply to this post by Martin Maechler

On 05 Nov 2013, at 14:22, Martin Maechler <[hidden email]> wrote:

>>>>>> Kenn Konstabel <[hidden email]>
>>>>>>    on Tue, 5 Nov 2013 13:25:20 +0200 writes:
>
>> I just tried it on ubuntu but within RStudio:
>>> cat("abc\b")
>> ab
>>> cat("abc\b\n")
>> ab
>>> sessionInfo()
>
> which --- as you allude to below --- shows that  RStudio  has changed R
> in so far that it adds a '\n'  even when R, i.e.  cat()  does not.
>
> I can understand that the RStudio programmers want to protect
> their users (*) from getting funny looking output,
> but I still don't like the fact that R inside RStudio is tweaked
> to behave differently from regular R.
>
> Martin Maechler, R Core Team & ETH Zurich
>
> --
> (*) or their software from malfunctioning when the console "looks ugly"

[…]

I agree with you Martin, but what is a "regular R"? Because on a Mac, R.app does exactly the same as RStudio:

> cat("abc\b")
ab
> cat("abc\b\n")
ab
> sessionInfo()
R version 3.0.2 (2013-09-25)
Platform: x86_64-apple-darwin10.8.0 (64-bit)

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base    

And this is R.app 1.62 Snow Leopard build (6558).

So, does it means that R run under R.app on Mac OS X is *not* considered as a regular R?
Best,

Philippe
 

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: cat with backspace and newline characters

Martin Maechler
>>>>> "PhGr" == Philippe Grosjean <[hidden email]>
>>>>>     on Tue, 5 Nov 2013 17:02:19 +0100 writes:

    PhGr> On 05 Nov 2013, at 14:22, Martin Maechler
    PhGr> <[hidden email]> wrote:

    >>>>>>> Kenn Konstabel <[hidden email]> on Tue, 5 Nov
    >>>>>>> 2013 13:25:20 +0200 writes:
    >>
    >>> I just tried it on ubuntu but within RStudio:
    >>>> cat("abc\b")
    >>> ab
    >>>> cat("abc\b\n")
    >>> ab
    >>>> sessionInfo()
    >>
    >> which --- as you allude to below --- shows that RStudio
    >> has changed R in so far that it adds a '\n' even when R,
    >> i.e.  cat() does not.
    >>
    >> I can understand that the RStudio programmers want to
    >> protect their users (*) from getting funny looking
    >> output, but I still don't like the fact that R inside
    >> RStudio is tweaked to behave differently from regular R.
    >>
    >> Martin Maechler, R Core Team & ETH Zurich
    >>
    >> --
    >> (*) or their software from malfunctioning when the
    >> console "looks ugly"

    PhGr> […]

    PhGr> I agree with you Martin, but what is a "regular R"?
    PhGr> Because on a Mac, R.app does exactly the same as
    PhGr> RStudio:

    >> cat("abc\b")
    PhGr> ab
    >> cat("abc\b\n")
    PhGr> ab
    >> sessionInfo()
    PhGr> R version 3.0.2 (2013-09-25) Platform:
    PhGr> x86_64-apple-darwin10.8.0 (64-bit)

    PhGr> locale: [1]
    PhGr> en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

    PhGr> attached base packages: [1] stats graphics grDevices
    PhGr> utils datasets methods base

    PhGr> And this is R.app 1.62 Snow Leopard build (6558).

    PhGr> So, does it means that R run under R.app on Mac OS X
    PhGr> is *not* considered as a regular R?  

good question....  I would have said so, but maybe we should
wait for my R core colleagues for a bit.... ;-)

Martin


    PhGr> Best, Philippe

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: cat with backspace and newline characters

Peter Dalgaard-2

On 05 Nov 2013, at 17:53 , Martin Maechler <[hidden email]> wrote:

>>>>>> "PhGr" == Philippe Grosjean <[hidden email]>
>>>>>>    on Tue, 5 Nov 2013 17:02:19 +0100 writes:
>
>    PhGr> On 05 Nov 2013, at 14:22, Martin Maechler
>    PhGr> <[hidden email]> wrote:
>
>>>>>>>> Kenn Konstabel <[hidden email]> on Tue, 5 Nov
>>>>>>>> 2013 13:25:20 +0200 writes:
>>>
>>>> I just tried it on ubuntu but within RStudio:
>>>>> cat("abc\b")
>>>> ab
>>>>> cat("abc\b\n")
>>>> ab
>>>>> sessionInfo()
>>>
>>> which --- as you allude to below --- shows that RStudio
>>> has changed R in so far that it adds a '\n' even when R,
>>> i.e.  cat() does not.
>>>
>>> I can understand that the RStudio programmers want to
>>> protect their users (*) from getting funny looking
>>> output, but I still don't like the fact that R inside
>>> RStudio is tweaked to behave differently from regular R.
>>>
>>> Martin Maechler, R Core Team & ETH Zurich
>>>
>>> --
>>> (*) or their software from malfunctioning when the
>>> console "looks ugly"
>
>    PhGr> […]
>
>    PhGr> I agree with you Martin, but what is a "regular R"?
>    PhGr> Because on a Mac, R.app does exactly the same as
>    PhGr> RStudio:
>
>>> cat("abc\b")
>    PhGr> ab
>>> cat("abc\b\n")
>    PhGr> ab
>>> sessionInfo()
>    PhGr> R version 3.0.2 (2013-09-25) Platform:
>    PhGr> x86_64-apple-darwin10.8.0 (64-bit)
>
>    PhGr> locale: [1]
>    PhGr> en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
>
>    PhGr> attached base packages: [1] stats graphics grDevices
>    PhGr> utils datasets methods base
>
>    PhGr> And this is R.app 1.62 Snow Leopard build (6558).
>
>    PhGr> So, does it means that R run under R.app on Mac OS X
>    PhGr> is *not* considered as a regular R?  
>
> good question....  I would have said so, but maybe we should
> wait for my R core colleagues for a bit.... ;-)
>

As far as I can tell, neither actually changes the output of cat(), witness

> cat("ab") ; cat("ab")
abab
>

So in a sense, it is the prompt that is tweaked to “jump to beginning of next line, unless already at beginning of line”. I don’t recall any “real” terminal having an escape sequence for that, but I wouldn’t put it past ESS to do something similar.

I see your point about cat(“pi”, pi), but I would expect that the bad habit would get cured first time it was attempted to print something between it and the next prompt. I’m actually more worried/puzzled that “\r” behaves strangely (in Rstudio, not R.app):

> cat("123");cat("\r456")
456
> cat("123\r");cat("456")
123456

People do sometimes use this pattern for displaying progress (e.g. iteration counts).


> Martin
>
>
>    PhGr> Best, Philippe
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel

--
Peter Dalgaard, Professor,
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Email: [hidden email]  Priv: [hidden email]

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: cat with backspace and newline characters

Yihui Xie-2
Yes, that indeed sounds like a problem, but example(txtProgressBar),
which is based on \r, works well in the RStudio console. Anyway,
thanks for all the experiments, and (to Renaud) support.rstudio.org is
the place to report such problems.

Regards,
Yihui
--
Yihui Xie <[hidden email]>
Web: http://yihui.name
Department of Statistics, Iowa State University
2215 Snedecor Hall, Ames, IA


On Tue, Nov 5, 2013 at 4:57 PM, peter dalgaard <[hidden email]> wrote:

>
>
> So in a sense, it is the prompt that is tweaked to “jump to beginning of next line, unless already at beginning of line”. I don’t recall any “real” terminal having an escape sequence for that, but I wouldn’t put it past ESS to do something similar.
>
> I see your point about cat(“pi”, pi), but I would expect that the bad habit would get cured first time it was attempted to print something between it and the next prompt. I’m actually more worried/puzzled that “\r” behaves strangely (in Rstudio, not R.app):
>
>> cat("123");cat("\r456")
> 456
>> cat("123\r");cat("456")
> 123456
>
> People do sometimes use this pattern for displaying progress (e.g. iteration counts).
>

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: cat with backspace and newline characters

Renaud Gaujoux
> Anyway,
> thanks for all the experiments, and (to Renaud) support.rstudio.org is
> the place to report such problems.
>

Funny how the post diverged to an RStudio-related issue.
Anyway, I posted a link to this post at support.rstudio.org:
http://support.rstudio.org/help/discussions/problems/9242-cat-with-backspace-and-newline-characters/

>From the user point of view, the following behaviour still feels like a
strange behaviour of the R prompt:

> cat("abc\b\b\b")
> c
(with the cursor now position on the 'c')

I don't know if there is a general official behaviour of prompt characters,
but I think one expects the prompt to always follow whatever is printed by
the previous R command, without corruption of the input line to be.

Renaud

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: cat with backspace and newline characters

Simon Urbanek

On Nov 6, 2013, at 3:47 AM, Renaud Gaujoux <[hidden email]> wrote:

>> Anyway,
>> thanks for all the experiments, and (to Renaud) support.rstudio.org is
>> the place to report such problems.
>>
>
> Funny how the post diverged to an RStudio-related issue.
> Anyway, I posted a link to this post at support.rstudio.org:
> http://support.rstudio.org/help/discussions/problems/9242-cat-with-backspace-and-newline-characters/
>
>> From the user point of view, the following behaviour still feels like a
> strange behaviour of the R prompt:
>
>> cat("abc\b\b\b")
>> c
> (with the cursor now position on the 'c’)

That is not strange at all - just try adding something like Sys.sleep(2) to understand it - it’s exactly what you should expect in a typical terminal (but see below) and it’s happens with any program (try perl -e 'print STDERR "abc\b\b\b"; sleep 1;’ for example).


> I don't know if there is a general official behaviour of prompt characters,
> but I think one expects the prompt to always follow whatever is printed by
> the previous R command, without corruption of the input line to be.
>

I don’t think that there is any guaranteed behavior for anything other than “\n”. All cat() guarantees is that this character sequence will be passed out to the console, there is no guarantee as to what effect it will actually have - that is entirely up to the front-end.

Thus your implicit assumption is that “\b” is interpreted in some way, but it’s not - it’s simply passed on. When running on a terminal, it is interpreted by the terminal, and the standard interpretation is to move the cursor to the left by one character. If running R through any other means like a GUI, it’s entirely up to the GUI to decide whether to interpret non-ASCI characters in some way - or not.

Cheers,
Simon



> Renaud
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: cat with backspace and newline characters

Renaud Gaujoux
I agree that the handling of \b is not that strange, once one agrees
on what \b actually means, i.e. "go back one character" and not
"delete previous character".
The fact that R GUI on Mac and Windows interprets/renders it
differently shows that normality and strangeness is quite relative
though.

To make my previous response clearer, I was just wondering if the
printing of R prompt character ">" after the evaluation of an
expression could detect trailing \b from cat in stdout/stderr and
shift its position so that it is displayed after the last printed
character. For example cat("abc\b\b\b") would give

abc>
and not
a> c

But this is:
0) Again platform, front-end dependent;
1) maybe not be possible (e.g., can we actually move forward without
printing a character that would erase the previous output?)
2) maybe not even desirable;
3) certainly not worth the effort anyway!

I guess we can happily close this thread :D
Many thanks.

Bests,
Renaud

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: cat with backspace and newline characters

Jari Oksanen

On 07/11/2013, at 09:35 AM, Renaud Gaujoux wrote:

> I agree that the handling of \b is not that strange, once one agrees
> on what \b actually means, i.e. "go back one character" and not
> "delete previous character".
> The fact that R GUI on Mac and Windows interprets/renders it
> differently shows that normality and strangeness is quite relative
> though.
>
As a user DEC LA120 terminal I expect the following:

> cat("a\b^\n")
â
>

Everything else feels like a bug.

Cheers, Jari Oksanen

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: cat with backspace and newline characters

Barry Rowlingson
In reply to this post by Renaud Gaujoux
On Thu, Nov 7, 2013 at 8:28 AM, Jari Oksanen <[hidden email]> wrote:
>
> On 07/11/2013, at 09:35 AM, Renaud Gaujoux wrote:
>
>> I agree that the handling of \b is not that strange, once one agrees
>> on what \b actually means, i.e. "go back one character" and not
>> "delete previous character".

It means, to paraphrase Humpty Dumpty from Alice in Wonderland,
whatever the terminal chooses it to mean. If you want to do something
meaningful and consistent across different terminals, you use termcap
or terminfo:

 http://en.wikipedia.org/wiki/Termcap
 http://en.wikipedia.org/wiki/Terminfo

or other abstractions probably built on that (eg 'ncurses').

> As a user DEC LA120 terminal I expect the following:
>
>> cat("a\b^\n")
> â
>>
>
> Everything else feels like a bug.

 Oh noes! I don't have a terminfo entry for my DEC LA120!

 I don't know what flavour of 'terminal' RStudio, the Windows GUI or
emacs-ess behave as and whether there's terminfo entries for them....

 Do any R packages link with termcap to do controlled screen output? Hmmmm....

Barry

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: cat with backspace and newline characters

Peter Dalgaard-2

On 07 Nov 2013, at 10:13 , Barry Rowlingson <[hidden email]> wrote:

> On Thu, Nov 7, 2013 at 8:28 AM, Jari Oksanen <[hidden email]> wrote:
>>
>> On 07/11/2013, at 09:35 AM, Renaud Gaujoux wrote:
>>
>>> I agree that the handling of \b is not that strange, once one agrees
>>> on what \b actually means, i.e. "go back one character" and not
>>> "delete previous character".
>
> It means, to paraphrase Humpty Dumpty from Alice in Wonderland,
> whatever the terminal chooses it to mean. If you want to do something
> meaningful and consistent across different terminals, you use termcap
> or terminfo:
>
> http://en.wikipedia.org/wiki/Termcap
> http://en.wikipedia.org/wiki/Terminfo
>
> or other abstractions probably built on that (eg 'ncurses').
>
>> As a user DEC LA120 terminal I expect the following:
>>
>>> cat("a\b^\n")
>> â
>>>
>>
>> Everything else feels like a bug.
>
> Oh noes! I don't have a terminfo entry for my DEC LA120!
>
> I don't know what flavour of 'terminal' RStudio, the Windows GUI or
> emacs-ess behave as and whether there's terminfo entries for them....
>
> Do any R packages link with termcap to do controlled screen output? Hmmmm....

Termcap or terminfo, make up your mind....

AFAIK, the readline library is linked to the term* databases (via ncurses, I suppose), so R-in-a-terminal is (usually) linked to them too. Insofar as there is any sanity left in building terminal interfaces, the sane thing would be to go via ncurses rather than outputting specific escape sequences.

Of course, there is nothing keeping you from doing silly things like

options(prompt="\033[2J> ")

or

options(prompt="\033[5mI eagerly and patiently await your command, oh Master \033[0m> ")

:-{)

-pd

--
Peter Dalgaard, Professor
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Email: [hidden email]  Priv: [hidden email]

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
12