-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy path.Rprofile
86 lines (71 loc) · 2.45 KB
/
.Rprofile
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
## local .Rprofile
# default repos
local({
r <- getOption("repos")
r["CRAN"] <- "https://cran.r-project.org"
options(repos=r)
})
# install package list
install_pkg <- function(pkg_list, force_update = TRUE, R_lib = NULL,
type = getOption("pkgType")) {
message("---------------------------------")
# current installed packages
cur_pkg_list <- NULL
if(missing(R_lib)) {
cur_pkg_list <- installed.packages()[,1]
} else {
cur_pkg_list <- installed.packages(lib.loc = R_lib)[,1]
}
# current installed and out-dated packages
old_pkg_list <- NULL
if(missing(R_lib)) {
old_pkg_list <- old.packages()[,1]
} else {
old_pkg_list <- old.packages(lib.loc = R_lib)[,1]
}
# package up-to-date
pkg_ok_list <- pkg_list[(pkg_list %in% cur_pkg_list) &
!(pkg_list %in% old_pkg_list)]
if(length(pkg_ok_list) > 0) {
message("-- Available and up-to-date packages:")
message(paste(pkg_ok_list, collapse = "\n"))
message("---------------------------------")
}
# package to update
pkg2update_list <- pkg_list[pkg_list %in% old_pkg_list]
if(length(pkg2update_list) > 0) {
message("-- Packages to update:")
message(paste(pkg2update_list, collapse = "\n"))
message("--> updating")
Sys.sleep(2)
if(missing(R_lib)) {
install.packages(pkg2update_list, type = type)
} else {
install.packages(pkg2update_list, lib = R_lib, type = type)
}
message("---------------------------------")
}
# missing package
missing_pkg_list <- pkg_list[!pkg_list %in% cur_pkg_list]
if(length(missing_pkg_list) > 0) {
message("-- Missing packages:")
message(paste(missing_pkg_list, collapse = "\n"))
message("--> installing")
Sys.sleep(2)
if(missing(R_lib)) {
install.packages(missing_pkg_list, type = type)
} else {
install.packages(missing_pkg_list, lib = R_lib, type = type)
}
message("---------------------------------")
}
}
## path to local directories
# project directory
proj_dir <- system("git rev-parse --show-toplevel", intern = TRUE)
# package source
src_dir <- file.path(proj_dir, "R-pkg")
# build directory
build_dir <- file.path(proj_dir, "build")
# dist directory
dist_dir <- file.path(build_dir, "dist")