RinWIN: Character eaten by cmd or Powershell? R.exe or Rterm.exe?

[This article was first published on B.I.S. dato, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Problem Description: When running R2.6.0(built with MinGW) in PowerShell (PS> /bin/R.exe), one can exit the running code with CTRL-C. However, the following situation is rather cratchy : the shell would (almost always) consequently omit the first character you type (for example, ls becomes “s” and hence is not recognized by shell anymore).

In the cmd.exe shell the same problem exists.

When I tried to start R again , the same problem is still there, some characters typed are “eaten” and all turn into a mess.

Answer: Use /Rterm.exe instead of ./R.exe to start R instance.

Explanation/Reason:

(Google with keyword “R.exe Rterm.exe”)
http://tolstoy.newcastle.edu.au/R/devel/04a/1055.html
Yes, that is indeed strange behaviour. 

Ctrl-C definitely presents problems.  For instance, on my WinXP system
running R from a Cygwin prompt, a Ctrl-C during the Sys.sleep kills
Rterm, whereas under the Windows cmd.exe prompt it works properly as
it did for you.

I can guess at an explanation for what you saw, but I don't know how
to fix it:

- R (as opposed to Rterm) is a small .exe program that does a little
argument parsing, then runs Rterm.  It looks as though the Ctrl-C is
going to R, and killing that process, but leaving the child process
Rterm running.  But since both Rterm and cmd.exe are reading and
writing to standard file handles, you get the messed up prompts.

I've just tried doing what the Windows documentation says should work
(adding this line before Rterm is called:

SetConsoleCtrlHandler(NULL, TRUE);  /* Ignore Ctrl-C; Rterm will
handle them */

but this didn't fix the problems, it just made them different (i.e.
Ctrl-C stopped working completely).  Rterm *does* set a Ctrl-C
handler, but it just isn't being called, as far as I can tell.

A simple workaround is to run Rterm or Rgui rather than R.  If anyone
knows a real fix, please let me know.

Duncan Murdoch

To leave a comment for the author, please follow the link and comment on their blog: B.I.S. dato.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)