1
1
# !/usr/bin/env Rscript
2
+
3
+ options(warn = 1 ) # print warnings immediately
4
+
2
5
args <- commandArgs(TRUE )
3
6
4
7
deptabfile = " r_deps.txt"
@@ -47,9 +50,20 @@ if(!file.exists("dl_r_pkgs.R")){
47
50
dlPkgVer <- function (pkgname , ver , destdir , skipExisting = TRUE ){
48
51
pkgfile <- paste0(pkgname ," _" ,ver ," .tar.gz" )
49
52
pkgpath <- file.path(destdir , pkgfile )
50
- url <- paste0(options(" repos" ), " /src/contrib/" , pkgfile )
53
+ url <- paste0(options(" repos" ), " /src/contrib/" ,pkgfile )
54
+ url_archive <- paste0(
55
+ options(" repos" ), " /src/contrib/Archive/" ,pkgname ," /" , pkgfile )
51
56
if (! file.exists(pkgpath ) || ! skipExisting ){
52
- download.file(url , destfile = pkgpath )
57
+ tryCatch({
58
+ # Suppress warning for every 404 error. This is normal if the
59
+ # package has moved to the Archive
60
+ suppressWarnings(
61
+ download.file(url , destfile = pkgpath )
62
+ )
63
+ }, error = function (e ){
64
+ download.file(url_archive , destfile = pkgpath )
65
+ })
66
+
53
67
}else {
54
68
message(" Skip " ,pkgfile ," (exists already)" )
55
69
}
@@ -60,6 +74,9 @@ if(options("repos") == "@CRAN@"){
60
74
options(repos = " https://cloud.r-project.org" )
61
75
}
62
76
deptab <- read.table(deptabfile , row.names = NULL , header = FALSE , stringsAsFactors = FALSE )
77
+
78
+ if (! dir.exists(dest )) dir.create(dest )
79
+
63
80
for (row in seq_len(nrow(deptab ))){
64
81
dlPkgVer(deptab [row ,1 ], deptab [row ,2 ], dest )
65
82
}
0 commit comments