When I start Emacs 24.4.1 for Windows with the -nw option, I am unable to start R via Meta+R. Emacs becomes unrensponsive and I have to kill the process.

The problem seems connected with the call in (R):

(inferior-ess r-start-args cust-alist gdbp)

By debugging I see r-start-args is set to "--no-readline", but I am not able to debug inferior-ess. In fact Edebug gives: Debugger entered: nil, without stepping through code.


Source of the problem

So the problem is in the ESS variable ess-microsoft-p. Defined as:

(defvar ess-microsoft-p (or (equal window-system 'w32)
                            (equal window-system 'win32)
                            (equal window-system 'mswindows))
  "Value is t if the OS is one of Microsoft's, nil otherwise.")

When you run Emacs from a Windows console, window-system is nil (because a character terminal is not at all a window system), therefore such is ess-microsoft-p. Eventually the predicate says that you are not running on a Microsoft OS!

The unpleasant now follows, in fact, as for Meta-R, we have:

(defun R (&optional start-args)
  "Call 'R', the 'GNU S' system from the R Foundation. .....
If you have certain command line arguments that should always be passed
to R, put them in the variable `inferior-R-args'."
  (let* ((r-always-arg
          (if (or ess-microsoft-p (eq system-type 'cygwin))
              "--ess "
            ;; else: "unix alike"
            (if (not ess-R-readline) "--no-readline ")))
          (concat r-always-arg
                  inferior-R-args " " ; add space just in case
  (inferior-ess r-start-args cust-alist gdbp)

As you can see if ess-microsoft-p is false and the system-type is not Cygwin, the function (R) assumes we are running Linux, therefore sets r-always-arg to --no-readline instead of -ess. This variable is appended to r-always-arg and passed to the command line invoking R thorough (inferior-ess).

--no-readline is a Unix only argument to invoke R, turning off command-line editing via readline. R will not start with this switch in Windows and Emacs will hang, infinitely waiting for R.

It should be noted that if you run a native Windows Emacs in a Cygwin console you incur in the same problem, since (eq system-type 'cygwin) is true when Emacs is compiled for Cygwin, not when running in Cygwin.


To me the current definition of ess-microsoft-p seems buggy.
Anyway you can fix it, adding in your init file, after starting ESS. i.e. (require 'ess-site):

(setq ess-microsoft-p t)


Now ess-microsoft-p is:

(defvar ess-microsoft-p (or (eq system-type 'ms-dos)
                (eq system-type 'windows-nt))
  "Value is t if the OS is one of Microsoft's, nil otherwise.")

system-type is independent from the windowing system, therefore ess-microsoft-p correctly reports t in Windows console too.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.