install-rtools.ps1 1.4 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# Install R Tools 4.0
Write-Output "Installing Rtools 4.0"

Write-Output "Downloading Rtools Last Version"
## download last relase name
$urlRtools = "https://cran.biotools.fr/bin/windows/Rtools/rtools40-x86_64.exe"
$outputRtools = 'c:\Windows\Temp\Rtools-win.exe'
$wcR = New-Object System.Net.WebClient

Write-Output "Downloading $urlRtools"
#Download the exe
$wcR.DownloadFile($urlRtools, $outputRtools)
Write-Output "Download completed $urlRtools"

$RtoolsDir = 'C:\Rtools\'
Write-Output "Install $outputRtools into $RtoolsDir"
Start-Process -FilePath $outputRtools -ArgumentList "/VERYSILENT /DIR=$RtoolsDir" -Wait -NoNewWindow

if ( Test-Path "HKLM:\Software\R-core\Rtools" ) {
	$Rtoolsver = (Get-ItemProperty -Path "HKLM:\Software\R-core\Rtools")."Current Version"
	Write-Output "Rtools version $Rtoolsver installed"
}
else {
	throw "ERROR: Can't install R $urlRtools"
}

# Add R to PATH
$oldpath = (Get-ItemProperty -Path 'Registry::HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment' -Name PATH).path
$newPath = "$oldpath;C:\Rtools\usr\bin"
Set-ItemProperty -Path 'Registry::HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment' -Name PATH -Value $newPath
[System.Environment]::SetEnvironmentVariable('MSYS2_PATH_TYPE', 'inherit', [System.EnvironmentVariableTarget]::Machine)
Jean-Francois Rey's avatar
Jean-Francois Rey committed
32
Add-Content C:\Rtools\msys2.ini "MSYS2_PATH_TYPE=inherit"
33
Remove-Item $outputRtools -Force