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

August 6, 2007
By

(This article was first published on B.I.S. dato, and kindly contributed to R-bloggers)

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 his blog: B.I.S. dato.

R-bloggers.com offers daily e-mail updates about R news and tutorials on topics such as: visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...



If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Comments are closed.