Repository navigation
Expand file tree
/
Copy pathInstallR_RStudio.ps1
More file actions
78 lines (54 loc) · 2.06 KB
/
Copy pathInstallR_RStudio.ps1
File metadata and controls
78 lines (54 loc) · 2.06 KB
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
##################################
#
# Author: Tomaz Kastrun
# Description: Installing R / RStudio
# silently using PS
# Date: 01.FEB.2019
# Blog: tomaztsql.wordpress.com
#
##################################
## Set working directory
$dir = "C:\DataTK\99_REnv\01_Source\"
Set-Location $dir
## Download RSTudio for Windows machine
# Version of RStudio is deliberatly set to specific version
# so that code is repeatable and always returns same results
$urlRStudio = "https://download1.rstudio.org/RStudio-1.1.463.exe"
$outputRStudio = "$dir\RStudio.exe"
$wcRStudio = New-Object System.Net.WebClient
$wcRStudio.DownloadFile($urlRStudio, $outputRStudio) # $PSScriptRoot
Write-Output "Download Completed"
## Download RSTudio for Windows machine
$urlR = "https://cran.r-project.org/bin/windows/base/R-3.5.2-win.exe"
$outputR = "$dir\R-win.exe"
$wcR = New-Object System.Net.WebClient
$wcR.DownloadFile($urlR, $outputR)
Write-Output "Download completed"
## Installing R / RStudio on desired Path
## Silent install
$dirRStudio = $dir + "RStudio.exe"
$dirR = $dir + "R-win.exe"
# "/c dir `"%systemdrive%\program files`""
Start-Process -FilePath $dirRStudio -ArgumentList "/S /v/qn"
Start-Process -FilePath $dirR -ArgumentList "/S /v/qn"
##
## Downloading R Packages just an example
##
$ListRPackages= Invoke-WebRequest -Uri "https://cran.r-project.org/bin/windows/contrib/3.5"
$ListRPackages.ParsedHtml
$pack = ($ListRPackages.ParsedHtml.getElementsByTagName(‘a’)).outerText
##
## Read the list of packages also from the list
##
$ListPackageLocation = "C:\DataTK\99_REnv\01_SourceList\packages.txt"
$PackList = Get-Content -Path $ListPackageLocation
$dir = "C:\DataTK\99_REnv\01_Source\"
ForEach ($Name in $PackList)
{
$UrlRoot = "https://cran.r-project.org/bin/windows/contrib/3.5/"
$url = $UrlRoot + $Name
$FileName = $dir +'\' + $Name
$PackagesOut = New-Object System.Net.WebClient
$PackagesOut.DownloadFile($url, $FileName)
Write-Output "Download Completed"
}