[GRASS-dev] [GRASS GIS] #1149: WinGrass - load R-installation-path
dynamically into PATH
GRASS GIS
trac at osgeo.org
Sat Sep 4 09:37:58 EDT 2010
#1149: WinGrass - load R-installation-path dynamically into PATH
-------------------------------+--------------------------------------------
Reporter: hellik | Owner: grass-dev@…
Type: enhancement | Status: new
Priority: normal | Milestone: 7.0.0
Component: Startup | Version: svn-trunk
Keywords: wingrass, path, R | Platform: MSWindows Vista
Cpu: x86-32 |
-------------------------------+--------------------------------------------
Hi,
at the moment the WinGrass-Installer reads the Windows-registry during
installation for the R-installation-path
http://trac.osgeo.org/grass/browser/grass/trunk/mswindows/GRASS-
Installer.nsi#L219
{{{
ReadRegStr $R_HKLM_INSTALL_PATH HKLM "Software\R-core\R" "InstallPath"
ReadRegStr $R_HKCU_INSTALL_PATH HKCU "Software\R-core\R" "InstallPath"
}}}
and writes this, if found, to the grassXX.bat
http://trac.osgeo.org/grass/browser/grass/trunk/mswindows/GRASS-
Installer.nsi#L728
{{{
${If} $R_HKLM_INSTALL_PATH != ""
FileWrite $0 'set PATH=$R_HKLM_INSTALL_PATH\bin;%PATH%$\r$\n'
${EndIf}
${If} $R_HKCU_INSTALL_PATH != ""
FileWrite $0 'set PATH=$R_HKCU_INSTALL_PATH\bin;%PATH%$\r$\n'
${EndIf}
}}}
this is a very statically approach to get the R-installation-path into the
%PATH% and R working in the Grass-delivered command-line. that means, if R
is upadated/upgraded, the Grass-delivered command-line can't find R in the
%PATH% anymore.
a dynamically approach to add the R-installation-path to %PATH% would be
better.
from the R-Windows-FAQ:
http://cran.r-project.org/bin/windows/base/rw-FAQ.html#Does-R-use-the-
Registry_003f
{{{
2.17 Does R use the Registry?
Not when R itself is running.
When you run the R installer, there are options (under `Select Additional
Tasks') to `Save version number in registry' and (for Administrator
installs) `Associate R with .RData files'.
If you tick the first option, the following string entries are added to
the Windows registry:
* HKEY_LOCAL_MACHINE\Software\R-core\R\Current Version contains the
version number, currently 2.11.1.
* HKEY_LOCAL_MACHINE\Software\R-core\R\[version]\InstallPath (where
[version] is currently 2.11.1) contains the path to the R home directory.
If you do not have administrative privileges on the machine while running
the installer, then the entries are created under HKEY_CURRENT_USER. As
from R 2.11.0 the same entries are also created under Software\R-core\R32
or Software\R-core\R64, for 32- and 64-bit R respectively.
If you tick the second option (shown with administrative privileges only)
(`Associate R with .RData files') then entries are created under
HKEY_CLASSES_ROOT\.RData and HKEY_CLASSES_ROOT\RWorkspace.
After installation you can add the Registry entries in by running
RSetReg.exe in the bin folder, and remove them by running this with
argument /U. Note that this requires administrative privileges unless run
with argument /Personal and neither sets up nor removes the file
associations.
}}}
the following code lines in the windows-command-line outputs the R
installation path:
{{{
reg query "HKLM\Software\R-core\R" /v "InstallPath"
}}}
or
{{{
reg query "HKCU\Software\R-core\R" /v "InstallPath"
}}}
in the following way:
{{{
C:\data\private\compiling_gis\detect_R_in_Dos>reg query
"HKLM\Software\R-core\R" /v "InstallPath"
HKEY_LOCAL_MACHINE\Software\R-core\R
InstallPath REG_SZ C:\Program Files\R\R-2.11.1
}}}
following line of code extract from the above output the R-installation
path and set a variable which could be added to %PATH%
{{{
set RegCommand=reg query "HKLM\Software\R-core\R" /v "InstallPath"
FOR /f "tokens=1-2* delims= " %%a IN ( ' %RegCommand% ^| find
"InstallPath" ' ) do set R_HKLM_INSTALL_PATH=%%c
}}}
or
{{{
set RegCommand2=reg query "HKCU\Software\R-core\R" /v "InstallPath"
FOR /f "tokens=1-2* delims= " %%a IN ( ' %RegCommand2% ^| find
"InstallPath" ' ) do set R_HKCU_INSTALL_PATH=%%c
}}}
but if there is no value in registry, following error comes up:
{{{
C:\data\private\compiling_gis\detect_R_in_Dos>FOR /F "tokens=1-2* delims=
" %a IN (' reg query "HKCU\Software\R-core\R" /v "InstallPath" | find
"InstallPath" '
) do set R_HKCU_INSTALL_PATH=%c
ERROR: registry key or value couldn't be found.
}}}
following questions:
- which of in the R-Windows-FAQ mentioned registry entries should be
tested?
- how could the above mentioned lines of code be added to grassXX.bad?
(I'm not really familiar with this kind of coding)
this would be nice in order to have a R-session working in the Grass-
delivered command line, independently if the R-installation has changed.
best regards
Helmut
--
Ticket URL: <http://trac.osgeo.org/grass/ticket/1149>
GRASS GIS <http://grass.osgeo.org>
Commonly referred to as GRASS, this is free Geographic Information System (GIS) software used for geospatial data management and analysis, image processing, graphics/maps production, spatial modeling, and visualization. GRASS is currently used in academic and commercial settings around the world, as well as by many governmental agencies and environmental consulting companies. GRASS is an official project of the Open Source Geospatial Foundation.
More information about the grass-dev
mailing list