[Rd] cat with backspace and newline characters

Simon Urbanek simon.urbanek at r-project.org
Thu Nov 7 01:41:57 CET 2013


On Nov 6, 2013, at 3:47 AM, Renaud Gaujoux <renaud at mancala.cbio.uct.ac.za> 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]]
> 
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
> 



More information about the R-devel mailing list