Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Install R & RTools from Windows terminal

I have a number of people @ work who I'd like to share some R scripts and other assorted goodies. This requires they have an instance of R and accompanying Rtools up and running and on their path. Adding something to the path is pretty easy to script but installing R and Rtools from windows command line is not (at least googling "install R from Windows command line" was not productive).

How can I install R and RTools from the windows terminal into the C:\ level directory (this can be made into a .bat file for clickable distribution)?

like image 928
Tyler Rinker Avatar asked May 26 '16 14:05

Tyler Rinker


3 Answers

I had to learn some bash but this script seems to work:

@echo off
If NOT exist "C:\R\R-3.3.0"\ (
bitsadmin  /transfer mydownloadjob  /download  /priority normal  ^
                  https://cran.r-project.org/bin/windows/base/R-3.3.0-win.exe C:\\Users\\%username%\Downloads\R-3.3.0-win.exe

C:\\Users\\%username%\Downloads\R-3.3.0-win.exe /VERYSILENT /DIR="C:\R\R-3.3.0"               
) 

If NOT exist "C:\Rtools\"\ (
bitsadmin  /transfer mydownloadjob  /download  /priority normal  ^
                  https://cran.r-project.org/bin/windows/Rtools/Rtools33.exe C:\\Users\\%username%\Downloads\Rtools33.exe

C:\\Users\\%username%\Downloads\Rtools33.exe /VERYSILENT /DIR="C:\Rtools\"
) 
like image 93
Tyler Rinker Avatar answered Oct 26 '22 22:10

Tyler Rinker


You're looking for the /VERYSILENT flag, see the R faq

Edit: forgot the /DIR="C:\" flag

like image 28
fedterzi Avatar answered Oct 26 '22 23:10

fedterzi


FWIW this is what I use. The chocolatey package for R and Rstudio works fine to get the latest versions. Then, I use a batch script to get latest Rtools. Note, I assume you have curl and grep available. Run as admin, I call this stuff separately from a main script that installs everything, but you could wrap it into one.

Get chocolatey

@echo off
setlocal
where choco > NUL || goto :getChoco
goto :EOF

:: chocolatey
:: https://github.com/chocolatey/choco/wiki/Installation
:getChoco
@powershell -NoProfile -ExecutionPolicy Bypass -Command "iex ((new-object net.webclient).DownloadString('https://chocolatey.org/install.ps1'))" && SET PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin

:EOF

Install R with choco

@echo off
setlocal
:: https://chocolatey.org/packages
choco install -y r.project

Install latest Rtools

@echo off
setlocal EnableExtensions
pushd "%~dp0"

set "uri=https://stat.ethz.ch/CRAN/bin/windows/Rtools/"

:: skip if already installed
if exist c:\Rtools goto :EOF

:: find latest version
for /f "tokens=1" %%i in ('curl -Ls "%uri%" ^|
                          grep -Poi -m 1 "Rtools[0-9]+\.exe"') do (
    set "latest=%%i"
)
if "x%latest%"=="x" (
    echo.error: Latest version of Rtools not found
    goto :EOF
)

:download
if not exist Rtools.exe (
    echo.Downloading Rtools from %uri%%latest%
    curl -Lo Rtools.exe "%uri%%latest%"
)

:install
if exist Rtools.exe (
   Rtools.exe /SILENT /SP- /NORESTART
) else echo.error: Rtools.exe not found
if exist "C:\Rtools" del Rtools.exe

popd
:EOF
like image 35
Rorschach Avatar answered Oct 26 '22 23:10

Rorschach