[ESS] Emacs finding "R" on Windows {was "Release of ESS 5.3.5"}

Phillip Lord phillip.lord at newcastle.ac.uk
Fri Aug 24 12:49:14 CEST 2007


>>>>> "MM" == Martin Maechler <maechler at stat.math.ethz.ch> writes:
 
  PL> Ah. I didn't know that windows internationalised that.

  MM> {{ AFAIK they've even internationalized the function names in
  MM>    Excel/Vbasic ...  the Horror-Land ... }}

Eech. 

  PL> For me (getenv "ProgramFiles") returns the right location though. So

  PL> (directory-files (concat (getenv "ProgramFiles") "\\R"))


  PL> Failing that

  PL> (executable-find "R.exe")

  PL> which is...

  PL> "c:/Program Files/R/R-2.5.1/bin/R.exe"

  PL> will work iff R is in the path.

  MM> (which it is not, I think, after a default installation of R on windows)

Sure. The ESS documentation says to put it in the path I think. Personally, I
would prefer to not have to do this; system path fiddling in a pain in the ass
and has to be done for each machine. 


  PL> After that,

  PL> HKEY_LOCAL_MACHINE\Software\R-core\R\Current Version

  PL> gives the current version


  PL> HKEY_LOCAL_MACHINE\Software\R-core\R\[version]\InstallPath

  PL> gives it's location. w32-regdat gives access to these values, although
  PL> this also requires an external executable.

  MM> Hmm, on the GNU emacs 22.1 (on Windows Server 2003) which I've got from
  MM> Vincent's, I don't seem to get anything from
  MM>    w32-regdat (variable)
  MM> or w32-regdat (function).

  MM> and the "emacs-official" w32-fns.el file full of Windows (NT) support
  MM> functions does not contain the string "regis" which would mean it has no
  MM> official e-lisp support for accessing the registry ?


Ah, sorry for being opaque. w32-regdat is part of EmacsW32 which is a nicely
prepackaged Emacs for windows. They've written some lisp to make the whole
process work nicely. 

http://www.ourcomments.org/Emacs/EmacsW32Util.html

I don't know how widely used this is among the ESS or Emacs on Windows
community in general. 


  PL> If I get the time, I'll try and write some lisp to get this to work.

  MM> That would be quite useful for the community, thank you in advance!

Well, just as a start, this returns the latest R version if you are using
EmacsW32 and have not told R not to modify the registry. It would be
interesting to run a straw poll; if people eval-region and see how many get
the correct answer. 

(defun ess-find-latest-r ()
  (or
   (and
    ;; is w32 available.
    (require 'w32-regdat nil t)
    ;; yes, so use this to find the latest version
    (ess-find-exists-p
     (concat
      (car 
       (w32-reg-iface-read-value
        (concat 
         "HKEY_LOCAL_MACHINE\\Software\\R-core\\R\\"
         (car 
          (w32-reg-iface-read-value 
           "HKEY_LOCAL_MACHINE\\Software\\R-core\\R\\Current Version")  )
         "\\InstallPath")))
      "\\bin\\R.exe")))))

(defun ess-find-exists-p(file)
  (and (file-exists-p file)
       (file-readable-p file)
       file))

 
(message "Latest R version %s" (ess-find-latest-r))

Phil




More information about the ESS-help mailing list