[Rd] cat with backspace and newline characters
peter dalgaard
pdalgd at gmail.com
Tue Nov 5 23:57:14 CET 2013
On 05 Nov 2013, at 17:53 , Martin Maechler <maechler at stat.math.ethz.ch> wrote:
>>>>>> "PhGr" == Philippe Grosjean <phgrosjean at sciviews.org>
>>>>>> on Tue, 5 Nov 2013 17:02:19 +0100 writes:
>
> PhGr> On 05 Nov 2013, at 14:22, Martin Maechler
> PhGr> <maechler at stat.math.ethz.ch> wrote:
>
>>>>>>>> Kenn Konstabel <lebatsnok at gmail.com> 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
>
> ______________________________________________
> R-devel at r-project.org 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: pd.mes at cbs.dk Priv: PDalgd at gmail.com
More information about the R-devel
mailing list