[R] Generating the Ctrl-M character

David Winsemius dwinsemius at comcast.net
Fri Nov 11 06:39:18 CET 2011

On Nov 10, 2011, at 11:55 PM, Jeff Newmiller wrote:

> Wow, Deadpan David.
> How about using the escape sequence "\r"?

So shoot me. It wasn't documented in a manner that I recognized in the  
places I looked.


And I did look at ?Quotes where "\r" is listed but did not know that  
it was == cntrl-M (if in fact it is.) I assumed (probably incorrectly)  
that ""\r" was cntrl-R. There was proabably a time in the past when I  
could have told you a lot of the decimal and maybe even hexadecimal  
equivalents for <cr>, <lf>, <beep>, but those days are behind me.

> Keep in mind that Ctrl-M is used as the end-of-line character on  
> some operating systems, so accomplishing this may not be portable,  
> and you didn't specify your operating system. On the three main  
> platforms (*nix, Windows/DOS, and Mac), "\r" should work, but "\n"  
> may get munged.

What? I very much doubt that any of those systems will not handle "\n"  
as expected. "\r" on the other hand I'm not so sure of.


> ---------------------------------------------------------------------------
> Jeff Newmiller                        The     .....       .....  Go  
> Live...
> DCN:<jdnewmil at dcn.davis.ca.us>        Basics: ##.#.       ##.#.   
> Live Go...
>                                      Live:   OO#.. Dead: OO#..   
> Playing
> Research Engineer (Solar/Batteries            O.O#.       #.O#.  with
> /Software/Embedded Controllers)               .OO#.       .OO#.   
> rocks...1k
> ---------------------------------------------------------------------------
> Sent from my phone. Please excuse my brevity.
> David Winsemius <dwinsemius at comcast.net> wrote:
>> On Nov 10, 2011, at 9:35 PM, Ashim Kapoor wrote:
>>> Dear R-helpers,
>>> I want to append a Ctrl-M character to a string and then save it to
>>> a text
>>> file.
>>> mystring<-"This is a test."
>>> # How do I add a Ctrl-M to it in the end ??
>>> cat(mystring,file="testfile")
>>> cntrl_m <- intToUtf8(13)
>>> cat(cntrl_m,file="testfile")
>> The resulting file seems to have a "blank line" in my editor.
>> -- 
>> David Winsemius, MD
>> West Hartford, CT
>> ______________________________________________
>> R-help at r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide
>> http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.

David Winsemius, MD
West Hartford, CT

More information about the R-help mailing list