| 1 | @Echo OFF
|
|---|
| 2 |
|
|---|
| 3 | :: Software and documentation is (c) 2013 GKX Associates Inc. and
|
|---|
| 4 | :: licensed under [GPL 2.0](http://www.gnu.org/licenses/gpl-2.0.html).
|
|---|
| 5 |
|
|---|
| 6 | :: Help is at bottom of script or just run script with single argument: help
|
|---|
| 7 |
|
|---|
| 8 | :: can optionally uncomment and change these to force certain values. This
|
|---|
| 9 | :: is normally unnecessary. Rather one can usually rely on the heuristics to
|
|---|
| 10 | :: set them.
|
|---|
| 11 | :: set R_CMD=R
|
|---|
| 12 | :: set R_HOME=%ProgramFiles%\R\R-2.14.0
|
|---|
| 13 | :: set R_ARCH=64
|
|---|
| 14 | :: set R_MIKTEX_PATH=%ProgramFiles%\MiKTeX 2.9\miktex\bin
|
|---|
| 15 | :: set R_TOOLS=C:\Rtools
|
|---|
| 16 | :: set MYSQL_HOME=%ProgramFiles%\MySQL\MysQL Server 5.1
|
|---|
| 17 |
|
|---|
| 18 | :: 1 means read registry and 0 means ignore registry
|
|---|
| 19 | if not defined R_REGISTRY set R_REGISTRY=1
|
|---|
| 20 | set CYGWIN=nodosfilewarning
|
|---|
| 21 |
|
|---|
| 22 | SetLocal EnableExtensions EnableDelayedExpansion
|
|---|
| 23 |
|
|---|
| 24 | ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
|---|
| 25 | :: R_CMD
|
|---|
| 26 | :: 1. if 1st arg is CMD then set R_CMD to R
|
|---|
| 27 | :: 2. else if 1st arg is Rshow, Rpath, Rgui, Rcmd, R or Rscript set R_CMD to it
|
|---|
| 28 | :: and remove it from args
|
|---|
| 29 | :: 3. else use R_CMD if set
|
|---|
| 30 | :: 4. else use %0
|
|---|
| 31 | ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
|---|
| 32 |
|
|---|
| 33 | set args=%*
|
|---|
| 34 | set cmd=
|
|---|
| 35 | if /i "%~1"=="registry" goto:Rregistry
|
|---|
| 36 | if /i "%~1"=="cd" set cmd=Rcd
|
|---|
| 37 | if /i "%~1"=="CMD" set cmd=Rcmd
|
|---|
| 38 | if /i "%~1"=="dir" set cmd=Rdir
|
|---|
| 39 | if /i "%~1"=="ls" set cmd=Rdir
|
|---|
| 40 | if /i "%~1"=="gui" set cmd=Rgui
|
|---|
| 41 | if /i "%~1"=="help" goto:Rhelp
|
|---|
| 42 | if /i "%~1"=="path" set cmd=Rpath
|
|---|
| 43 | if /i "%~1"=="R" set cmd=R
|
|---|
| 44 | if /i "%~1"=="script" set cmd=Rscript
|
|---|
| 45 | if /i "%~1"=="show" set cmd=RShow
|
|---|
| 46 | if /i "%~1"=="SetReg" set cmd=RSetReg
|
|---|
| 47 | if /i "%~1"=="tools" set cmd=Rtools
|
|---|
| 48 | if /i "%~1"=="touch" set cmd=Rtouch
|
|---|
| 49 |
|
|---|
| 50 | if "%cmd%"=="" goto:R_CMD_cont
|
|---|
| 51 | if "%2"=="" (set args=) && goto:R_CMD_cont
|
|---|
| 52 | set args=xxx%*
|
|---|
| 53 | call set args=%%args:xxx%1=%%
|
|---|
| 54 | :R_CMD_cont
|
|---|
| 55 | if defined cmd set R_CMD=%cmd%
|
|---|
| 56 | if not defined R_CMD set R_CMD=%0
|
|---|
| 57 | :: set "R_CMD=%R_CMD:.bat=%"
|
|---|
| 58 | for %%i in ("%R_CMD%") do set R_CMD=%%~ni
|
|---|
| 59 | if /i "%R_CMD%"=="#Rscript" set R_CMD=Rscript
|
|---|
| 60 | rem echo R_CMD:%R_CMD% args=[%args%]
|
|---|
| 61 |
|
|---|
| 62 | :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
|---|
| 63 | :: 1. If .\Rgui.exe exist use implied R_PATH and skip remaining points.
|
|---|
| 64 | :: 2. If .\{x64,i386}\Rgui.exe or .\bin\{x64,i386}\Rgui.exe exists use implied R_HOME.
|
|---|
| 65 | :: 3. if R_HOME defined then derive any of R_ROOT and R_VER that
|
|---|
| 66 | :: are not already defined.
|
|---|
| 67 | :: 4. if R_PATH defined then derive any of R_ROOT, R_HOME, R_VER and R_ARCH that
|
|---|
| 68 | :: are not already defined.
|
|---|
| 69 | :: 4a. If R_REGISTRY=1 and R found in registry derive any of R_HOME, R_ROOT and
|
|---|
| 70 | :: R_VER that are not already defined.
|
|---|
| 71 | :: 5. If R_ROOT not defined try %ProgramFiles%\R\*, %ProgramFiles(x86)%\R\*
|
|---|
| 72 | :: and then %SystemRoot%\R else error
|
|---|
| 73 | :: 6. If R_VER not defined use last directory in cd %R_ROOT% & dir /od
|
|---|
| 74 | :: 7. if R_ARCH not defined try %R_ROOT%\%R_VER%\bin\x64\Rgui.exe and then
|
|---|
| 75 | :: %R_ROOT%\%R_VER%\bin\i386\Rgui.exe
|
|---|
| 76 | :: 8. If R_ROOT, R_VER and R_ARCH defined skip remaining points.
|
|---|
| 77 | :: 9. If Rgui.exe found on PATH use implied R_PATH.
|
|---|
| 78 | :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
|---|
| 79 |
|
|---|
| 80 | :: 1
|
|---|
| 81 | if exist Rgui.exe (
|
|---|
| 82 | pushd ..\..
|
|---|
| 83 | set R_HOME=!CD!
|
|---|
| 84 | popd
|
|---|
| 85 | goto:R_exe_end
|
|---|
| 86 | )
|
|---|
| 87 |
|
|---|
| 88 | :: 2
|
|---|
| 89 | if exist x64\Rgui.exe (
|
|---|
| 90 | pushd ..
|
|---|
| 91 | set R_PATH=!CD!\bin\x64
|
|---|
| 92 | popd
|
|---|
| 93 | goto:R_exe_end
|
|---|
| 94 | )
|
|---|
| 95 | if exist i386\Rgui.exe (
|
|---|
| 96 | pushd ..
|
|---|
| 97 | set R_PATH=!CD!\bin\i386
|
|---|
| 98 | popd
|
|---|
| 99 | goto:R_exe_end
|
|---|
| 100 | )
|
|---|
| 101 | if exist bin\x64\Rgui.exe set R_PATH=%CD%\bin\x64 & goto:R_exe_end
|
|---|
| 102 | if exist bin\i386\Rgui.exe set R_PATH=%CD%\bin\i386
|
|---|
| 103 | :R_exe_end
|
|---|
| 104 |
|
|---|
| 105 | :: 3
|
|---|
| 106 |
|
|---|
| 107 | if defined R_HOME (
|
|---|
| 108 | pushd
|
|---|
| 109 | cd %R_HOME%
|
|---|
| 110 | if not defined R_VER for /f "delims=" %%a in ("!CD!") do set R_VER=%%~na
|
|---|
| 111 | cd ..
|
|---|
| 112 | if not defined R_ROOT set R_ROOT=!CD!
|
|---|
| 113 | popd
|
|---|
| 114 | )
|
|---|
| 115 |
|
|---|
| 116 | :: 4
|
|---|
| 117 | if defined R_PATH (
|
|---|
| 118 | pushd
|
|---|
| 119 | cd %R_PATH%
|
|---|
| 120 | if not defined R_ARCH for /f "delims=" %%a in ("!CD!") do set R_ARCH=%%~na
|
|---|
| 121 | cd ..\..
|
|---|
| 122 | if not defined R_HOME set R_HOME=!CD!
|
|---|
| 123 | if not defined R_VER for /f "delims=" %%a in ("!CD!") do set R_VER=%%~na
|
|---|
| 124 | cd ..
|
|---|
| 125 | if not defined R_ROOT set R_ROOT=!CD!
|
|---|
| 126 | popd
|
|---|
| 127 | )
|
|---|
| 128 |
|
|---|
| 129 |
|
|---|
| 130 | :: 4a
|
|---|
| 131 |
|
|---|
| 132 | if not defined R_HOME for /f "tokens=2*" %%a in (
|
|---|
| 133 | 'reg query hklm\software\wow6432Node\r-core\r /v InstallPath 2^>NUL ^| findstr InstallPath'
|
|---|
| 134 | ) do set R_HOME=%%~b
|
|---|
| 135 |
|
|---|
| 136 | if not defined R_HOME for /f "tokens=2*" %%a in (
|
|---|
| 137 | 'reg query hklm\software\R-core\R /v InstallPath 2^>NUL ^| findstr InstallPath'
|
|---|
| 138 | ) do set R_HOME=%%~b
|
|---|
| 139 |
|
|---|
| 140 | if defined R_HOME (
|
|---|
| 141 | if not defined R_ROOT (
|
|---|
| 142 | pushd %R_HOME%
|
|---|
| 143 | cd ..
|
|---|
| 144 | set R_ROOT=!CD!
|
|---|
| 145 | popd
|
|---|
| 146 | )
|
|---|
| 147 | if not defined R_VER (
|
|---|
| 148 | for /f "delims=" %%a in ("%R_HOME%") do set R_VER=%%~nxa
|
|---|
| 149 | )
|
|---|
| 150 | )
|
|---|
| 151 |
|
|---|
| 152 |
|
|---|
| 153 | :: 5
|
|---|
| 154 |
|
|---|
| 155 | if defined R_ROOT goto:R_ROOT_end
|
|---|
| 156 | if exist "%ProgramFiles%\R" set R_ROOT=%ProgramFiles%\R
|
|---|
| 157 | if defined R_ROOT goto:R_ROOT_end
|
|---|
| 158 | if exist %SystemDrive%\R set R_ROOT=%SystemDrive%\R
|
|---|
| 159 | :R_ROOT_end
|
|---|
| 160 |
|
|---|
| 161 | :: 6
|
|---|
| 162 | if defined R_VER goto:R_VER_end
|
|---|
| 163 | for /f "delims=" %%a in (
|
|---|
| 164 | 'dir /b /od /ad "%R_ROOT%" 2^>NUL'
|
|---|
| 165 | ) do set R_VER=%%a
|
|---|
| 166 | :R_VER_end
|
|---|
| 167 |
|
|---|
| 168 | :: do we need this?
|
|---|
| 169 | if defined R_ROOT if defined R_VER set R_HOME=%R_ROOT%\%R_VER%
|
|---|
| 170 |
|
|---|
| 171 | :: 7
|
|---|
| 172 | if defined R_ARCH goto:R_ARCH_cont
|
|---|
| 173 | set R_ARCH=i386
|
|---|
| 174 | if exist "%R_HOME%\bin\x64" set R_ARCH=x64
|
|---|
| 175 | if exist "%R_ROOT%\%R_VER%\bin\x64" set R_ARCH=x64
|
|---|
| 176 | :R_ARCH_cont
|
|---|
| 177 | if "%R_ARCH%"=="64" set R_ARCH=x64
|
|---|
| 178 | if "%R_ARCH%"=="32" set R_ARCH=i386
|
|---|
| 179 | if "%R_ARCH%"=="386" set R_ARCH=i386
|
|---|
| 180 |
|
|---|
| 181 | :: 8
|
|---|
| 182 | if not defined R_ROOT goto:where
|
|---|
| 183 | if not defined R_VER goto:where
|
|---|
| 184 | if not defined R_ARCH goto:where
|
|---|
| 185 | set R_PATH=%R_ROOT%\%R_VER%\bin\%R_ARCH%
|
|---|
| 186 | goto:path_end
|
|---|
| 187 |
|
|---|
| 188 | echo "R not found" & exit /b 1
|
|---|
| 189 |
|
|---|
| 190 | :: 9
|
|---|
| 191 | :where
|
|---|
| 192 | where Rgui.exe 1>NUL 2>NUL
|
|---|
| 193 | if not errorlevel 1 for /f "delims=" %%a in ('where Rgui.exe') do set R_PATH=%%~pa
|
|---|
| 194 |
|
|---|
| 195 | :path_end
|
|---|
| 196 |
|
|---|
| 197 | :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
|---|
| 198 | :: R_TOOLS
|
|---|
| 199 | :: 1. use R_TOOLS if defined. If not
|
|---|
| 200 | :: 2. check if ls.exe, rsync.exe and gcc.exe are on PATH. If not
|
|---|
| 201 | :: 3. check if Rtools found in registry. If not
|
|---|
| 202 | :: 4. check if C:\Rtools exists. If not
|
|---|
| 203 | :: 5. R_TOOLS not found.
|
|---|
| 204 | :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
|---|
| 205 |
|
|---|
| 206 | if defined R_TOOLS goto:RtoolsEnd
|
|---|
| 207 |
|
|---|
| 208 | where ls.exe 1> NUL 2> NUL
|
|---|
| 209 | if errorlevel 1 goto:RtoolsNotOnPATH
|
|---|
| 210 |
|
|---|
| 211 | where rsync.exe 1> NUL 2> NUL
|
|---|
| 212 | if errorlevel 1 goto:RtoolsNotOnPATH
|
|---|
| 213 |
|
|---|
| 214 | where gcc.exe 1> NUL 2> NUL
|
|---|
| 215 | if errorlevel 1 goto:RtoolsNotOnPATH
|
|---|
| 216 |
|
|---|
| 217 | for /f "delims=" %%a in ('where rsync.exe') do set R_TOOLS=%%~pa
|
|---|
| 218 | pushd %R_TOOLS%
|
|---|
| 219 | cd ..
|
|---|
| 220 | set R_TOOLS=%CD%
|
|---|
| 221 | popd
|
|---|
| 222 | goto:RtoolsEnd
|
|---|
| 223 |
|
|---|
| 224 | :RtoolsNotOnPATH
|
|---|
| 225 |
|
|---|
| 226 | if not defined R_TOOLS for /f "tokens=2*" %%a in (
|
|---|
| 227 | 'reg query hklm\software\R-core\Rtools /v InstallPath 2^>NUL ^| findstr InstallPath'
|
|---|
| 228 | ) do set R_TOOLS=%%~b
|
|---|
| 229 | if not defined R_TOOLS for /f "tokens=2*" %%a in (
|
|---|
| 230 | 'reg query hklm\software\wow6432Node\Rtools /v InstallPath 2^>NUL ^| findstr InstallPath'
|
|---|
| 231 | ) do set R_TOOLS=%%~b
|
|---|
| 232 |
|
|---|
| 233 | if exist "C:\Rtools" set R_TOOLS=C:\Rtools
|
|---|
| 234 |
|
|---|
| 235 | :RToolsEnd
|
|---|
| 236 |
|
|---|
| 237 | :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
|---|
| 238 | :: R_TOOLS_PATH
|
|---|
| 239 | :: Extract path from: %R_TOOLS%\unins000.dat
|
|---|
| 240 | :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
|---|
| 241 |
|
|---|
| 242 | if defined R_TOOLS call :extract_string {app} %R_TOOLS%\unins000.dat
|
|---|
| 243 | call set R_TOOLS_PATH=%%final:{app}=%R_TOOLS%%%
|
|---|
| 244 | call :trimPath:R_TOOLS_PATH
|
|---|
| 245 |
|
|---|
| 246 | if defined R_TOOLS for /f "tokens=3" %%a in (%R_TOOLS%\Version.txt) do set R_TOOLS_VERSION=%%a
|
|---|
| 247 |
|
|---|
| 248 | :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
|---|
| 249 | :: R_MIKTEX
|
|---|
| 250 | :: If R_MIKTEX defined use that
|
|---|
| 251 | :: else if pdflatex.exe on PATH use that else
|
|---|
| 252 | :: check %ProgramFiles%\miktex* else
|
|---|
| 253 | :: check %ProgramFiles(x86)%\miktex* else
|
|---|
| 254 | :: check %SystemDrive%\miktex*
|
|---|
| 255 | :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
|---|
| 256 |
|
|---|
| 257 | if defined R_MIKTEX_PATH goto:miktex_end
|
|---|
| 258 |
|
|---|
| 259 | :: if pdflatex.exe found in PATH use implied path
|
|---|
| 260 | where pdflatex.exe 1>NUL 2>NUL
|
|---|
| 261 | if errorlevel 1 goto:miktex_continue
|
|---|
| 262 | set MIKTEX_ALREADY_ON_PATH=1
|
|---|
| 263 | for /f "delims=" %%a in ('where pdflatex.exe') do set R_MIKTEX_PATH=%%~pa
|
|---|
| 264 | :: remove trailing \, if any
|
|---|
| 265 | IF "%R_MIKTEX_PATH:~-1%"=="\" SET R_MIKTEX_PATH=%R_MIKTEX_PATH:~0,-1%
|
|---|
| 266 |
|
|---|
| 267 | goto:miktex_end
|
|---|
| 268 |
|
|---|
| 269 | :miktex_continue
|
|---|
| 270 | if not defined R_MIKTEX_PATH for /f "delims=" %%a in (
|
|---|
| 271 | 'dir /b /on "%ProgramFiles%"\miktex* 2^>NUL'
|
|---|
| 272 | ) do set R_MIKTEX_PATH=%ProgramFiles%\%%a\miktex\bin
|
|---|
| 273 |
|
|---|
| 274 | if not defined R_MIKTEX_PATH for /f "delims=" %%a in (
|
|---|
| 275 | 'dir /b /on "%ProgramFiles(x86)%"\miktex* 2^>NUL'
|
|---|
| 276 | ) do set R_MIKTEX_PATH=%ProgramFiles%\%%a\miktex\bin
|
|---|
| 277 |
|
|---|
| 278 | if not defined R_MIKTEX_PATH for /f "delims=" %%a in (
|
|---|
| 279 | 'dir /b /on %SystemDrive%:\miktex* 2^>NUL'
|
|---|
| 280 | ) do set R_MIKTEX_PATH=%SystemDrive%:\%%a\mixtex\bin
|
|---|
| 281 |
|
|---|
| 282 | :miktex_end
|
|---|
| 283 |
|
|---|
| 284 | :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
|---|
| 285 | :: MySQL
|
|---|
| 286 | :: If MYSQL_HOME defined use that else
|
|---|
| 287 | :: check %ProgramFiles%\MySQL\* else
|
|---|
| 288 | :: check %SystemDrive%:\MySQL\*
|
|---|
| 289 | :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
|---|
| 290 |
|
|---|
| 291 | :: if not defined MYSQL_HOME for /f "delims=" %%a in (
|
|---|
| 292 | :: 'dir /b /on "%ProgramFiles%"\MySQL\* 2^>NUL'
|
|---|
| 293 | :: ) do set MYSQL_HOME=%ProgramFiles%\MySQL\%%a
|
|---|
| 294 | ::
|
|---|
| 295 | :: if not defined MYSQL_HOME for /f "delims=" %%a in (
|
|---|
| 296 | :: 'dir /b /on %SystemDrive%:\MySQL* 2^>NUL'
|
|---|
| 297 | :: ) do set R_MIKTEX=%SystemDrive%:\MySQL\%%a
|
|---|
| 298 |
|
|---|
| 299 | :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
|---|
| 300 | :: get name by which program was called - $0
|
|---|
| 301 | :: or use R_CMD environment variable if that was defined (mainly for testing)
|
|---|
| 302 | :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
|---|
| 303 |
|
|---|
| 304 | if not defined R_CMD (set R_CMD=%0)
|
|---|
| 305 | for %%i in ("%R_CMD%") do set R_CMD=%%~ni
|
|---|
| 306 | if /i "%R_CMD%"=="dir" goto:Rdir
|
|---|
| 307 | if /i "%R_CMD%"=="cd" goto:Rcd
|
|---|
| 308 | if /i "%R_CMD%"=="touch" goto:Rtouch
|
|---|
| 309 | if /i "%R_CMD%"=="Rversions" goto:RSetReg
|
|---|
| 310 |
|
|---|
| 311 | :: add MiKTeX to PATH if not already on it
|
|---|
| 312 | if not defined R_MIKTEX_PATH goto :miktex_add_path_end
|
|---|
| 313 | echo %PATH% | findstr /i miktex 1>NUL 2>NUL
|
|---|
| 314 | if errorlevel 1 path %R_MIKTEX_PATH%;%PATH%
|
|---|
| 315 | :miktex_add_path_end
|
|---|
| 316 |
|
|---|
| 317 | :: add Rtools paths to PATH if not already on it
|
|---|
| 318 | if not defined R_TOOLS_PATH goto :Rtools_add_path_end
|
|---|
| 319 | echo %PATH% | findstr /i Rtools 1>NUL 2>NUL
|
|---|
| 320 | if errorlevel 1 path %R_TOOLS_PATH%;%PATH%
|
|---|
| 321 | :Rtools_add_path_end
|
|---|
| 322 |
|
|---|
| 323 | if /i "%R_CMD%"=="Rpath" goto:Rpath
|
|---|
| 324 | if /i "%R_CMD%"=="Rtools" goto:Rtools
|
|---|
| 325 | if /i "%R_CMD%"=="Rcd" goto:Rcd
|
|---|
| 326 | if /i "%R_CMD%"=="Rdir" goto:Rdir
|
|---|
| 327 | if /i "%R_CMD%"=="Rshow" goto:Rshow
|
|---|
| 328 | if /i "%R_CMD%"=="Rtouch" goto:Rtouch
|
|---|
| 329 | if /i "%R_CMD%"=="RSetReg" goto:RSetReg
|
|---|
| 330 |
|
|---|
| 331 |
|
|---|
| 332 | if /i not "%R_CMD%"=="Rgui" goto:notRgui
|
|---|
| 333 | start "Rgui.exe" "%R_PATH%\Rgui.exe" %args%
|
|---|
| 334 | goto:eof
|
|---|
| 335 |
|
|---|
| 336 | :notRgui
|
|---|
| 337 | "%R_PATH%\%R_CMD%.exe" %args%
|
|---|
| 338 |
|
|---|
| 339 | goto:eof
|
|---|
| 340 |
|
|---|
| 341 | :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
|---|
| 342 | :: output the set statements
|
|---|
| 343 | :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
|---|
| 344 | :Rshow
|
|---|
| 345 |
|
|---|
| 346 | if defined R_PATH (
|
|---|
| 347 | set old=%CD%
|
|---|
| 348 | cd %R_PATH%
|
|---|
| 349 | for /f "delims=" %%a in ("!CD!") do set R_ARCH=%%~nxa
|
|---|
| 350 | cd ..\..
|
|---|
| 351 | set R_HOME=!CD!
|
|---|
| 352 | for /f "delims=" %%a in ("!CD!") do set R_VER=%%~nxa
|
|---|
| 353 | cd ..
|
|---|
| 354 | set R_ROOT=!CD!
|
|---|
| 355 | cd !old!
|
|---|
| 356 | )
|
|---|
| 357 |
|
|---|
| 358 | :: echo set R_PATH=%R_PATH%
|
|---|
| 359 | :: echo set R_HOME=%R_HOME%
|
|---|
| 360 | :: echo set R_ROOT=%R_ROOT%
|
|---|
| 361 | :; echo set R_VER=%R_VER%
|
|---|
| 362 | :: echo set R_ARCH=%R_ARCH%
|
|---|
| 363 | :: echo set R_TOOLS=%R_TOOLS%
|
|---|
| 364 | :: echo set R_TOOLS_PATH=%R_TOOLS_PATH%
|
|---|
| 365 | :: :: echo set MYSQL_HOME=%MYSQL_HOME%
|
|---|
| 366 | ::echo set R_MIKTEX_PATH=%R_MIKTEX_PATH%
|
|---|
| 367 | set R
|
|---|
| 368 | goto:eof
|
|---|
| 369 |
|
|---|
| 370 | :Rcd
|
|---|
| 371 | endlocal & cd %R_ROOT%
|
|---|
| 372 | goto:eof
|
|---|
| 373 |
|
|---|
| 374 | :Rdir
|
|---|
| 375 | dir/od "%R_ROOT%"
|
|---|
| 376 | goto:eof
|
|---|
| 377 |
|
|---|
| 378 | :RSetReg
|
|---|
| 379 | cd %R_PATH%
|
|---|
| 380 | RSetReg %args%
|
|---|
| 381 | goto:eof
|
|---|
| 382 |
|
|---|
| 383 | :: if not XP then check if running with Admin privs. If not give msg and exit.
|
|---|
| 384 | :Rtouch
|
|---|
| 385 | ver | findstr XP >NUL
|
|---|
| 386 | if not errorlevel 1 goto:Rtouch_next
|
|---|
| 387 | if not exist "%ProgramFiles%\R" goto:Rtouch_next
|
|---|
| 388 | reg query "HKU\S-1-5-19" >NUL 2>&1 && ( goto Rtouch_next ) || (
|
|---|
| 389 | echo Please run this as Administator.
|
|---|
| 390 | goto :eof
|
|---|
| 391 | )
|
|---|
| 392 | :Rtouch_next
|
|---|
| 393 |
|
|---|
| 394 | if not defined R_HOME set R_HOME=%R_ROOT%\%R_VER%
|
|---|
| 395 | pushd %R_HOME%
|
|---|
| 396 | echo > dummy.txt
|
|---|
| 397 | del dummy.txt
|
|---|
| 398 | popd
|
|---|
| 399 | goto:eof
|
|---|
| 400 |
|
|---|
| 401 |
|
|---|
| 402 |
|
|---|
| 403 | :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
|---|
| 404 | :: set path
|
|---|
| 405 | :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
|---|
| 406 | :Rpath
|
|---|
| 407 | endlocal & PATH %PATH%;%R_PATH%
|
|---|
| 408 | goto:eof
|
|---|
| 409 |
|
|---|
| 410 | :Rtools
|
|---|
| 411 | endlocal & PATH %PATH%
|
|---|
| 412 | goto:eof
|
|---|
| 413 |
|
|---|
| 414 | :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
|---|
| 415 | :: list R versions
|
|---|
| 416 | :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
|---|
| 417 | :Rversions
|
|---|
| 418 | if defined args goto:Rversions_cont
|
|---|
| 419 | pushd %R_HOME%
|
|---|
| 420 | cd ..
|
|---|
| 421 | echo R packages found. Most recent (last listed) is default:
|
|---|
| 422 | for /f "delims=" %%a in ('dir/b /od') do echo %%~fa
|
|---|
| 423 | popd
|
|---|
| 424 | goto:eof
|
|---|
| 425 | :Rversions_cont
|
|---|
| 426 | set args=###%args%
|
|---|
| 427 | set args=%args:### =%
|
|---|
| 428 | set args=%args:###=%
|
|---|
| 429 | pushd %R_HOME%
|
|---|
| 430 | cd ..
|
|---|
| 431 | (for /f "delims=" %%a in ('dir /b /od') do echo %%~fa) | findstr /L /C:"%args%" 1>NUL 2>NUL
|
|---|
| 432 | if errorlevel 1 echo %args% not found & goto:eof
|
|---|
| 433 | echo Run the following command (may need an elevated cmd window):
|
|---|
| 434 | for /f "delims=" %%a in ('dir /b /on ^| findstr /L /C:"%args%"') do @echo echo ^> "%%~fa\dummy.txt" /Y
|
|---|
| 435 | popd
|
|---|
| 436 | goto:eof
|
|---|
| 437 |
|
|---|
| 438 | :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
|---|
| 439 | :: list registry entries
|
|---|
| 440 | :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
|---|
| 441 |
|
|---|
| 442 | :Rregistry
|
|---|
| 443 | reg query hklm\software\R-core\R /v InstallPath 2>NUL | findstr InstallPath
|
|---|
| 444 | reg query hklm\software\wow6432Node\r-core\r /v InstallPath 2>NUL | findstr InstallPath
|
|---|
| 445 |
|
|---|
| 446 | goto:eof
|
|---|
| 447 |
|
|---|
| 448 | :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
|---|
| 449 | ::
|
|---|
| 450 | :: Extract text from file:
|
|---|
| 451 | :: %1 = input string that starts text
|
|---|
| 452 | :: %2 = input file
|
|---|
| 453 | :: final = output variable holding text from and including %1 until
|
|---|
| 454 | :: binary data encountered
|
|---|
| 455 | ::
|
|---|
| 456 | :: Needs: SetLocal EnableExtensions EnableDelayedExpansion
|
|---|
| 457 | ::
|
|---|
| 458 | :: Example:
|
|---|
| 459 | :: call :extract_string {app} C:\Rtools\unins000.dat
|
|---|
| 460 | :: echo %final%
|
|---|
| 461 | :: where {app} is the string that starts extraction and
|
|---|
| 462 | :: C:\Rtoolsiunins000.dat is the file
|
|---|
| 463 | ::
|
|---|
| 464 | :: Based on code by Frank Westlake, https://github.com/FrankWestlake
|
|---|
| 465 | ::
|
|---|
| 466 | :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
|---|
| 467 |
|
|---|
| 468 | :extract_string
|
|---|
| 469 |
|
|---|
| 470 | SetLocal EnableExtensions EnableDelayedExpansion
|
|---|
| 471 |
|
|---|
| 472 | Set "string=%1"
|
|---|
| 473 | Set "file=%2"
|
|---|
| 474 |
|
|---|
| 475 | For /F "delims=" %%a in (
|
|---|
| 476 | 'findstr /C:"%string%" "%file%"^|MORE'
|
|---|
| 477 | ) Do (
|
|---|
| 478 | Set "$=%%~a"
|
|---|
| 479 | If /I "!$:~0,5!" EQU "%string%" (
|
|---|
| 480 | Set $=!$:;=" "!
|
|---|
| 481 | For %%b in ("!$!") Do (
|
|---|
| 482 | Set "#=%%~b"
|
|---|
| 483 | If "!#:~0,5!" EQU "%string%" (
|
|---|
| 484 | CALL :work "!#!"
|
|---|
| 485 | )
|
|---|
| 486 | )
|
|---|
| 487 | )
|
|---|
| 488 | )
|
|---|
| 489 | endlocal & set final=%final%
|
|---|
| 490 | Goto :EOF
|
|---|
| 491 | :work
|
|---|
| 492 | set final=%final%!#!;
|
|---|
| 493 | Goto :EOF
|
|---|
| 494 |
|
|---|
| 495 | ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
|---|
| 496 | :trimPath:<variable to trim> [segment to add]
|
|---|
| 497 | :: Eliminates redundant path segments from the variable and
|
|---|
| 498 | :: optionally adds new segmants.
|
|---|
| 499 | :: Example: CALL :trimPath:PATH
|
|---|
| 500 | :: Example: CALL :trimPath:PATH "C:\A & B" C:\a\b\c
|
|---|
| 501 | ::
|
|---|
| 502 | :: Note that only a colon separates the subroutine name and
|
|---|
| 503 | :: the name of the variable to be edited.
|
|---|
| 504 | :: - Frank Westlake, https://github.com/FrankWestlake
|
|---|
| 505 | SetLocal EnableExtensions EnableDelayedExpansion
|
|---|
| 506 | For /F "tokens=2 delims=:" %%a in ("%0") Do (
|
|---|
| 507 | For %%a in (%* !%%a!) Do (
|
|---|
| 508 | Set "#=%%~a"
|
|---|
| 509 | For %%b in (!new!) Do If /I "!#!" EQU "%%~b" Set "#="
|
|---|
| 510 | If DEFINED # (
|
|---|
| 511 | If DEFINED new (Set "new=!new!;!#!") Else ( Set "new=!#!")
|
|---|
| 512 | )
|
|---|
| 513 | )
|
|---|
| 514 | )
|
|---|
| 515 | EndLocal & For /F "tokens=2 delims=:" %%a in ("%0") Do Set "%%a=%new%"
|
|---|
| 516 | Goto :EOF
|
|---|
| 517 |
|
|---|
| 518 | ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
|---|
| 519 |
|
|---|
| 520 | :Rhelp
|
|---|
| 521 |
|
|---|
| 522 | echo (c) 2013 G. Grothendieck
|
|---|
| 523 | echo License: GPL 2.0 ( http://www.gnu.org/licenses/gpl-2.0.html )
|
|---|
| 524 | echo Launch script for R and associated functions.
|
|---|
| 525 | echo Usage: R.bat [subcommand] [arguments]
|
|---|
| 526 | echo Subcommands where (0) means takes no arguments; (A) means may need Admin priv
|
|---|
| 527 | echo cd - cd to R_ROOT, typically to C:\Program Files\R (0)
|
|---|
| 528 | echo cmd - Run Rcmd.exe
|
|---|
| 529 | echo dir - List contents of R_ROOT in chronological order showing R versions (0)
|
|---|
| 530 | echo gui - Run Rgui.exe
|
|---|
| 531 | echo help - Help info (0)
|
|---|
| 532 | echo path - Add R_TOOLS, R_MIKTEX ^& R_PATH to path for this cmd line session (0)
|
|---|
| 533 | echo R - Run R.exe (0)
|
|---|
| 534 | echo script - Run Rscript.exe
|
|---|
| 535 | echo show - Show R_ variable values used. R_PATH, etc. (0)
|
|---|
| 536 | echo SetReg - Run RSetReg; see 2.17 in R FAQ for Windows (A)
|
|---|
| 537 | echo tools - Add R_TOOLS and R_MIKTEX to path for this cmd line session (0)
|
|---|
| 538 | echo touch - Change date on R_HOME to now (0) (A)
|
|---|
| 539 | echo Examples
|
|---|
| 540 | echo R -- invoke R.exe R gui -- invoke Rgui.exe
|
|---|
| 541 | echo R dir -- show R versions R show -- show R_ variables
|
|---|
| 542 | echo R CMD build mypkg -- builds mypkg
|
|---|
| 543 | echo cmd /c set R_VER=R-2.14.0 ^& R gui -- run indicated Rgui version
|
|---|
| 544 | echo cmd /c set R_ARCH=32 ^^^& R gui -- run 32 bit Rgui
|
|---|
| 545 | echo cmd /c R_VER=R-2.14.0 ^^^& R setreg - make 2.14.0 current in registry
|
|---|
| 546 | echo cmd /c R_VER=R-2.14.0 ^^^& R.bat touch - change date on R-2.14.0 dir to now
|
|---|
| 547 | goto:eof
|
|---|
| 548 | echo.
|
|---|
| 549 | echo Run Rgui using a different version of R. R_HOME only affects R session
|
|---|
| 550 | echo but not cmd line session.
|
|---|
| 551 | echo cmd /c set R_HOME=%ProgramFiles%\R\R-2.14.0 ^& R gui
|
|---|
| 552 | echo
|
|---|
| 553 | echo Launch a new cmd line window in which R_HOME is as set and launch R:
|
|---|
| 554 | echo start set R_HOME=%ProgramFiles%\R\R-2.14.0 ^& R gui
|
|---|
| 555 | echo
|
|---|
| 556 | echo ==Customization by renaming==
|
|---|
| 557 | echo.
|
|---|
| 558 | echo If the optional first argument is missing then it uses the value of
|
|---|
| 559 | echo the environment variable R_CMD or if that is not set it uses the name of
|
|---|
| 560 | echo the script file as the default first argument. The idea is one could have
|
|---|
| 561 | echo multiple versions of the script called R.bat, Rgui.bat, etc. which invoke
|
|---|
| 562 | echo the corresponding functionality without having to specify first argument.
|
|---|
| 563 | echo.
|
|---|
| 564 | echo ==Customization by setting environment variables at top of script==
|
|---|
| 565 | echo.
|
|---|
| 566 | echo It can be customized by setting any of R_CMD, R_HOME, R_ARCH,
|
|---|
| 567 | echo R_MIKTEX_PATH, R_TOOLS after the @echo off command at the top of the
|
|---|
| 568 | echo script. R_CMD will be used as the default first argument (instead of the
|
|---|
| 569 | echo script name).
|
|---|
| 570 | echo.
|
|---|
| 571 | echo e.g. use the following after @echo off to force 32-bit
|
|---|
| 572 | echo set R_ARCH=32
|
|---|
| 573 | echo.
|
|---|
| 574 | echo e.g. use the following after @echo off to force a particular version of
|
|---|
| 575 | echo R to be used
|
|---|
| 576 | echo set R_HOME=%ProgramFiles%\R\R-2.14.0
|
|---|
| 577 | echo.
|
|---|
| 578 | echo e.g. use the following after @echo off to change the default command to
|
|---|
| 579 | echo Rgui even if the script is called myRgui.bat, say:
|
|---|
| 580 | echo set R_CMD=Rgui
|
|---|
| 581 | echo.
|
|---|
| 582 | echo ==Installation==
|
|---|
| 583 | echo.
|
|---|
| 584 | echo The script is self contained so just place it anywhere on your Windows
|
|---|
| 585 | echo PATH. (From the Windows cmd line the command PATH shows your current
|
|---|
| 586 | echo Windows path.) You may optionally make copies of this script with names
|
|---|
| 587 | echo like R.bat, Rscript.bat, Rcmd.bat so that each has a different default.
|
|---|
| 588 | echo.
|
|---|
| 589 |
|
|---|