-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpackages.R
124 lines (113 loc) · 3.29 KB
/
packages.R
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# This script sets up library that R will have available. It starts by
# installing 4 packages:
# "versions"
# All other package installations use this package to control the package
# version number. However, the latest version of this package is always
# installed. As a result, changes to this package could change the behavior of
# this script.
# "devtools"
# Used first to make sure Rtools is installed. Later used to install any
# github repositories.
# "Rcpp"
# Allows R to use C++. Required by a number of packages. Trying to install
# this through dependency installation led to lots of problems. Installing
# by itself fixed those issues.
# "tidyverse"
# Installs lots of packages as dependencies. This eliminates the need to keep
# track of them all. Also used to read the csv file that list any additional
# CRAN or github packages needed.
#
# Once these four packages are complete, this script reads the CRAN and GitHub
# csv files. Each lists any packages needed along with their versions.
#
# In this way, you can be 99% confident that the exact same R environment will
# be created on multiple machines. The only uncontrolled package is the initial
# "versions" package.
#
# One final note concerning packages in private repositories. They are not
# handled by this script. After setting up R, any private repos must be
# installed manually.
# This script is called from the command line
# with an argument holding the R folder name.
args <- commandArgs(trailingOnly = TRUE)
r_dir <- args[1]
# Set the library variable for all packages
lib <- file.path(getwd(), r_dir, "library")
# install package "versions"
install.packages(
"versions",
repos= "https://cran.rstudio.com/",
lib = lib,
dependencies = TRUE,
quiet = TRUE
)
library(versions, quietly = TRUE)
# Install package "devtools"
install.versions(
"devtools",
"1.12.0",
lib = lib,
dependencies = TRUE,
quiet = TRUE
)
library(devtools, quietly = TRUE)
# Check that a development environment is present (Rtools).
# This is required to install packages from GitHub.
setup <- setup_rtools()
suppressWarnings(
suppressMessages(
tryCatch(
has_devel(),
error = function(e) {
cat("\nRtools not found. Install Rtools before running 2 - setup.bat")
quit(save = "no", status = 1)
}
)
)
)
# Install package "Rcpp"
install.versions(
"Rcpp",
"0.12.11",
lib = lib,
dependencies = TRUE,
quiet = TRUE
)
# Install package "tidyverse"
install.versions(
"tidyverse",
"1.1.1",
lib = lib,
dependencies = TRUE,
quiet = TRUE
)
library(tidyverse, quietly = TRUE)
# Read the csv of additional CRAN packages to install and install them
cran_csv <- read_csv("CRAN_packages.csv")
if (nrow(cran_csv) > 0){
install.versions(
cran_csv$Package,
cran_csv$Version,
lib = lib,
dependencies = TRUE,
quiet = TRUE
)
}
# Read the csv of GitHub packages to install and install them
gh_csv <- read_csv("GitHub_packages.csv")
if (nrow(gh_csv) > 0){
for (r in 1:nrow(gh_csv)){
pkg <- gh_csv$Package[r]
repo <- gh_csv$repo[r]
ref <- gh_csv$ref[r]
if (suppressWarnings(!require(pkg, character.only = TRUE, lib.loc = lib))){
install_github(
repo = repo,
ref = ref,
lib = lib,
dependencies = TRUE,
quiet = TRUE
)
}
}
}