[ESS] feature request: look more places for R on windows [code]
Ross Boylan
ross at biostat.ucsf.edu
Thu Mar 28 21:51:19 CET 2013
Since I'm on Windows I thought I'd give it a whirl. This seems to work
for me; how general it is, I don't know. i386 is hardcoded into the path.
I was a little concerned the final setq would only reset
inferior-R-program-name inside the expression, but it seems to reset the
global value.
(defun installPath-reg-read (regpath)
;read a path in the Windows registry. This probably works for string
;values only. If the path does not exist, it returns nil.
;Adapted from source:
;http://stackoverflow.com/questions/7436530/can-i-read-the-windows-registry-from-within-elisp-how
(let ((reg.exe (concat (getenv "windir") "\\system32\\reg.exe"))
tokens last-token)
(setq reg-value (shell-command-to-string (concat reg.exe " query " regpath " /v InstallPath"))
tokens (split-string reg-value nil t)
last-token (nth (1- (length tokens)) tokens))
(and (not (string= last-token "value.")) last-token)))
(defun r-executable ()
; get full path of R executable. Assumes 32 bit architecture.
(setq fullpath (or (installPath-reg-read "HKCU\\Software\\R-core\\R")
(installPath-reg-read "HKLM\\Software\\R-core\\R")))
(if fullpath
(concat fullpath "\\bin\\i386\\Rterm.exe")))
(if (eq system-type 'windows-nt)
(setq inferior-R-program-name (r-executable)))
Note this simply tries to get the "best" path rather than locating all
available versions.
Further background below.
On 3/28/2013 12:30 PM, Rodney Sparapani wrote:
> On 03/28/2013 01:42 PM, Ross Boylan wrote:
>> BTW, the path is available in the registry at
>> HKEY_CURRENT_USER\Software\R-core\R\2.15.3 under InstallPath. There is
>> also an entry that uses \R32\ instead of \R\ in the registry tree.
>
> Something like this has been suggested before (for example, see the
> discussion from June 15th). There are a few problems here:
>
> 1) Generally, ESS developers are not cracker-jack Windows developers.
> 2) There have been MAJOR changes in Windows especially 7 and 8
> which may (or may not) be at issue here; for example, multi-user
> installs of ESS require omniscience.
> 3) it is not obvious to me why we need to search both the
> HKLM and HKCU root keys (and perhaps others as well?!?).
HKLM holds information from system-wide installs, while HKCU has info
from installs as a regular user. So this is somewhat related to 2,
since 2 makes installs as a regular user more likely (that's what
happened with me).
It seems to me there should be functions that present an integrated view
of the registry, giving HKCU if available and HKLM otherwise. But, even
if they exist, I don't know if emacs exposes them.
Google finds
http://stackoverflow.com/questions/7436530/can-i-read-the-windows-registry-from-within-elisp-how
and the package
http://marmalade-repo.org/packages/w32-registry
which apparently uses the same technique. A bit ugly.
H:\>reg query HKCU\Software\R-core\R /v InstallPath
HKEY_CURRENT_USER\Software\R-core\R
InstallPath REG_SZ C:\Users\rdboylan\Documents\R\R-2.15.3
H:\>reg query HKLM\Software\R-core\R /v InstallPath
ERROR: The system was unable to find the specified registry key or value.
It looks as if the path without the version number provides the most
recent location.
>
> So, I don't see this suggestion being acted on UNLESS there is
> a Windows developer lurking out there who wants to work on ESS.
> But, thanks anyways ;o)
>
More information about the ESS-help
mailing list