@echo off rem See thread 'Variables in batch file not being set when inside IF?!', rem December 9, 2009 [http://goo.gl/0VDW] for why the following is needed. @setlocal EnableDelayedExpansion rem ###################################################################### rem # Usage: RCMDprompt.bat [working path] [Rversion] rem # rem # Arguments: rem # [working path] - Set working directory. Default is "%UserProfile%". rem # [Rversion] - name of directory where R is installed. If not rem # given, the current version is identified from the rem # Windows Registry. rem # rem # Examples: rem # RCMDprompt.bat rem # RCMDprompt.bat "%UserProfile%\myR\" R-2.10.0pat rem # RCMDprompt.bat "%UserProfile%\myR\" rem # RCMDprompt.bat "" R-2.11.0dev rem # RCMDprompt.bat "" R-2.6.2 "" jit rem # RCMDprompt.bat "" R-2.12.0 "i386" rem # RCMDprompt.bat "" R-2.12.0 "x64" rem # rem # This script opens a Window command prompt with a enviroment variables rem # set, and the starts the R terminal. When quitting R, control is rem # returned to the Windows command prompt. rem # rem # NOTE: This scripts works even if Cygwin is installed. HOWEVER, you rem # can not have any Cygwin applications running (not even a shell or rem # XEmacs for Cygwin) at the same time you try to run RCMD. rem # rem # Last updated: 2010-11-15 rem # rem # Requires: rem # To run R (Rterm): rem # (i) Install R [1] where the installer suggests, e.g. under rem # "%ProgramFiles%\R\R-2.10.0". rem # rem # To build and install packages: rem # (ii) Install "Rtools" in C:\Rtools\, which is the default [2]. rem # (iii) Install Microsoft HTML Help Compiler [4]. If it is already rem # installed the installer will tell you not to install it. rem # rem # To compile LaTeX R documentation: rem # (iv) Install MikTeX [4]. Tune it by instructions at [5], because rem # there are recent issues with MikTeX v2.4 and R. The problem rem # occurs because e-TeX is used instead of TeX. See [5] for rem # details. Try latex -version. If you see "MikTeX-e-TeX" then rem # you should read the instructions at [5]. rem # rem # The default setup of the script assumes default installation paths. rem # rem # Reference: rem # [1] R, rem # http://www.r-project.org/ rem # [2] "Rtools" and "Win64No_toolchain" rem # http://www.murdoch-sutherland.com/Rtools/ rem # [3] Microsoft HTML Help Compiler, rem # http://msdn.microsoft.com/library/tools/htmlhelp/chm/HH1Start.htm rem # [4] MikTeX, rem # http://www.miktex.org/ rem # [5] Duncan Murdoch, Using MiKTeX with R for Windows, 2004. rem # http://www.murdoch-sutherland.com/Rtools/miktex.html rem # [6] MinGW rem # http://www.mingw.org/ rem # [7] Brian Ripley, Re: [Rd] Locale problems with too-fancy quotes in rem # Windows CMD.exe, r-devel mailing list, Sept 20, 2007. rem # [8] Stephen Milborrow, The Ra Extension to R - a just-in-time rem # (JIT) for R, 2008. http://www.milbo.users.sonic.net/ra/ rem # [9] Python, http://www.python.org/download/, 2008. rem # [10] Command-line SVN client for Windows, rem # http://subversion.tigris.org/getting.html, e.g. rem # http://www.sliksvn.com/ rem # [11] GNU Scientific Library, http://www.gnu.org/software/gsl/ rem # [12] Henrik Bengtsson, R.batch package, R-forge, 2009, rem # http://r-forge.r-project.org/projects/r-dots/ rem # rem # Henrik Bengtsson, hb@biostat.ucsf.edu, 2004-2010. rem ###################################################################### rem # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - rem # 1. Process arguments rem # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - set WORKDIR="%1%" IF "%WORKDIR%" == """" ( set WORKDIR= ) IF "%WORKDIR%" == "" ( set WORKDIR=%HOME% ) set R_VERSION=%2% IF "%R_VERSION%" == """" ( set R_VERSION= ) set R_ARCH=%3% IF "%R_ARCH%" == "i386" ( set R_ARCH=i386 ) ELSE ( set R_ARCH=x64 ) set R_USEJIT=%4% IF "%R_USEJIT%" == "jit" ( set R_USEJIT=1 ) ELSE ( set R_USEJIT=0 ) rem # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - rem # 2. Setup minimal PATH for Windows rem # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - rem # Store the default PATH (will be appended at the end) set PATH0=%PATH% rem # Clear the PATH path ; rem # Add 'reg' to the PATH rem path %SystemRoot%;%PATH%; rem %SystemRoot%\system32;%PATH%; rem # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - rem # 3. Setup HOME and TMPDIR rem # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - rem # Set the HOME directory. This is the directory where R looks rem # for the .Rprofile and .Renviron files. See ?Startup. set HOME=%UserProfile% rem # Set TMPDIR to a temporary directory set TMPDIR=%TEMP% rem # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - rem # 4. "Global" environment variables rem # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - rem # Short version of PROGRAMFILES, e.g. 'C:\Progra~1' instead of rem # 'C:\Program Files\', which contains spaces that are BAD for R & Co. rem # rem # On Windows XP and NT, variable substitution using 'for' can be used rem # to do this automatically from %ProgramFiles%. For details see rem # http://www.microsoft.com/windowsxp/home/using/productdoc/en/for.asp for %%v in ("%ProgramFiles%") do set PROGRAMFILES_SHORT=%%~sv for %%v in ("%ProgramFiles(x86)%") do set PROGRAMFILESX86_SHORT=%%~sv rem # AD HOC 2010-09-28 set PROGRAMFILES_SHORT=%SystemDrive%\PROGRA~1 rem # Set the main R directory set R_ROOT=%PROGRAMFILES_SHORT%\R rem # Settings for R CMD check (cannot be set in ~/.Renviron) set _R_CHECK_LICENSE_=true rem # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - rem # Additional R CMD check settings rem # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - IF EXIST "%HOME%/.R/check.conf" ( echo Detected an R CMD check configuration file: %HOME%/.R/check.conf ) rem # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - rem # 6. Setup R_HOME rem # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - IF "%R_VERSION%" == "" ( rem # Figuring out the default install path for R from the Registry %SystemRoot%\system32\reg QUERY HKEY_LOCAL_MACHINE\Software\R-core\R /v "InstallPath" | %SystemRoot%\system32\findstr "InstallPath" > %TEMP%\RCurrentVersion.tmp for /F "tokens=2,*" %%G in (%TEMP%\RCurrentVersion.tmp) do echo %%H > %TEMP%\RCurrentVersion.tmp rem Make sure R_HOME user Window short filenames for /F "delims=" %%G in (%TEMP%\RCurrentVersion.tmp) do set R_HOME=%%~sG rem Update the R file version string for /F "delims=" %%G in (%TEMP%\RCurrentVersion.tmp) do set R_VERSION=%%~nG%%~xG del /F %TEMP%\RCurrentVersion.tmp ) ELSE ( set R_HOME=%R_ROOT%\%R_VERSION% ) rem echo R_HOME=%R_HOME% rem echo R_ARCH=%R_ARCH% rem # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - rem # 7. Setup the PATH rem # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - rem # Set the R_HOME directory where R [1] is installed IF "%R_USEJIT%" == "1" ( set dir=%R_HOME%\bin-ra echo Using JIT version of R ) ELSE ( set dir=%R_HOME%\bin\%R_ARCH% ) IF NOT EXIST "%dir%" ( set dir=%R_HOME%\bin ) rem # It is important that %R_HOME%\bin is before R tools\bin!!! path %dir% IF NOT EXIST "%dir%" ( echo ERROR: R binary path was not found at "%dir%". Make sure the 2nd option to RCMDprompt is correct. pause 0 exit /b 1 ) rem # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - rem # 7.5 Ask R itself what the R version is rem # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - echo R_VERSION=%R_VERSION% rem Example: R_VERSION_N_N=2_15 Rterm --vanilla --slave -e "cat(gsub('[.]', '_', gsub('[.].$', '', getRversion()))); quit('no');" > %TEMP%\RCurrentVersion.tmp for /F "delims=" %%G in (%TEMP%\RCurrentVersion.tmp) do set R_VERSION_N_N=%%G del /F %TEMP%\RCurrentVersion.tmp echo R_VERSION_N_N=%R_VERSION_N_N% rem Example: R_VERSION_NN=215 set R_VERSION_NN=%R_VERSION_N_N:~0,1%%R_VERSION_N_N:~2,2% echo R_VERSION_NN=%R_VERSION_NN% rem # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - rem # 90. Infer library paths rem # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Rterm --vanilla --slave -e "cat(.libPaths()[1])" > %TEMP%\R_LIBPATHS.tmp for /F "delims=" %%G in (%TEMP%\R_LIBPATHS.tmp) do set R_LIBPATHS_1=%%~sG echo Detected R library path: %R_LIBPATHS_1% set R_LIBS=%USERPROFILE%\R\win-library\%R_VERSION_N_N% echo R_LIBS=%R_LIBS% rem # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - rem # 8. Add all of Rtools to PATH rem # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - echo Setting up Rtools... rem # Set the Rtools [2] directory set RTOOLS_ROOT=%SystemDrive%\Rtools!R_VERSION_NN! set dir=%RTOOLS_ROOT%\bin IF NOT EXIST "!dir!" ( set RTOOLS_ROOT=%SystemDrive%\Rtools set dir=!RTOOLS_ROOT!\bin IF NOT EXIST "!dir!" ( set RTOOLS_ROOT= ) ) IF EXIST "!dir!" ( echo - RTOOLS_ROOT=!RTOOLS_ROOT! path !PATH!;!dir! ) else ( echo - WARNING: Failed to locate Rtools. ) rem # Set the gcc-4.6.3 [6] directory *that comes with [2]* set dir=%RTOOLS_ROOT%\gcc-4.6.3\bin IF EXIST "!dir!" ( echo - Rtools/gcc-4.6.3: !dir! path !PATH!;!dir! ) rem # Set the MinGW64 [6] directory *that comes with [2]* set dir=%RTOOLS_ROOT%\MinGW64\bin IF EXIST "!dir!" ( echo - Rtools/MinGW64: !dir! path !PATH!;!dir! ) rem # Set the MinGW [6] directory *that comes with [2]* set dir=%RTOOLS_ROOT%\MinGW\bin IF EXIST "!dir!" ( echo - Rtools/MinGW: !dir! path !PATH!;!dir! ) rem # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - rem # OBSOLETE since (at least) R v2.14.0 rem # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - rem rem # Set the Rtools/Perl [2] directory rem set dir=%RTOOLS_ROOT%\perl\bin rem path %PATH%;%dir% rem IF NOT EXIST "%dir%" ( rem echo WARNING: Non-existing path added to PATH: "%dir%" rem ) echo Setting up Rtools...done rem # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - rem # OBSOLETE since (at least) R v2.14.0 rem # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - rem rem # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - rem rem # 9. Add addtional build/developers tools for R to PATH rem rem # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - rem rem # Set the Microsoft HTML Help Compiler [3] directory rem set dir=%ProgramFiles%\HTML Help Workshop rem path %PATH%;%dir% rem IF NOT EXIST "%dir%" ( rem echo WARNING: Non-existing path added to PATH: "%dir%" rem ) echo Adding optional software to PATH... rem # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - rem # 10. Optional things you might want to have on your search path rem # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - s rem # Add the MinGW [6] directory set dir=%SystemDrive%\MinGW\bin IF EXIST "!dir!" ( echo - Standalone MinGW: !dir! path !PATH!;!dir! ) rem # Add Ghostscript binary set R_GSCMD=%ProgramW6432%\gs\gs8.71\bin\gswin32c.exe rem # GNU Scientific Library (GSL) [11] set dir=%PROGRAMFILESX86_SHORT%\GnuWin32\bin IF EXIST "!dir!" ( echo - GNU Scientific Library [GSL]: !dir! path !PATH!;%dir% ) rem # GTK+ set dir=%ProgramW6432%\GTK2-Runtime\bin IF EXIST "!dir!" ( echo - GTK+: !dir! path !PATH!;%dir% ) rem # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - rem # 11. MikTeX rem # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - rem # Add MikTeX default installation set dir=%ProgramFiles%\MiKTeX 2.9\miktex\bin set dir=%ProgramFiles(x86)%\MiKTeX 2.9\miktex\bin IF EXIST "!dir!" ( echo - MikTeX: !dir! path !PATH!;!dir! ) rem # Add Rd.sty etc to the TeX search path set TEXINPUTS=%TEXINPUTS%;%R_HOME%/share/texmf rem # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - rem # 12. Optional Python (used to SVN datasets for Bioconductor.org) rem # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - rem # Add the Python [9] directory set dir=%SystemDrive%\Python25 IF EXIST "!dir!" ( echo - Python: !dir! path !PATH!;!dir! ) rem # Add the SVN [10] directory set dir=%ProgramW6432%\SlikSvn\bin IF EXIST "!dir!" ( echo - SlikSvn: !dir! path !PATH!;!dir! rem # See http://goo.gl/HFhqd for the below set SVN_SSH="C:\\Program Files\\PuTTY\\plink.exe" ) set dir=%ProgramFiles%\Subversion\bin IF EXIST "!dir!" ( echo - Subversion: !dir! path !PATH!;!dir! ) rem # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - rem # 91. GNU Extras (optional) rem # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - set dir=%ProgramFiles%\GnuWin32\bin IF EXIST "!dir!" ( echo - GnuWin32 ["GNU Extras"]: !dir! path !PATH!;!dir! ) rem # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - rem # 92. R.batch package [12] (optional) rem # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Rterm --vanilla --slave -e "cat(system.file('bin', package='R.batch'))" > %TEMP%\DIR.tmp for /F "delims=" %%G in (%TEMP%\DIR.tmp) do set dir=%%~sG IF EXIST "!dir!" ( echo - R.batch: !dir! path !PATH!;!dir! ) rem # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - rem # 93. Biocep-R (optional) rem # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - set dir=%R_ROOT% IF EXIST "!dir!" ( echo - Biocep-R: !dir! path !PATH!;!dir! ) echo Adding optional software to PATH...done rem # Appended default PATH at the end set PATH=%PATH%;%PATH0% rem # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - rem # 11. Start the MSDOS prompt in the given directory rem # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - rem # Change directory according to argument 1 cd /D "%WORKDIR%" rem # 'CHange CodePage' in order to display some symbols correctly [7] rem # This is for western country users, so you might want to skip it. chcp 1252 rem # Report R version Rterm --vanilla --version rem # Start the MSDOS command prompt "%SystemRoot%\system32\cmd.exe"