/
install-url.r
42 lines (37 loc) · 1.41 KB
/
install-url.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
#' Install a package from a url
#'
#' This function is vectorised so you can install multiple packages in
#' a single command.
#'
#' @param url location of package on internet. The url should point to a
#' zip file, a tar file or a bzipped/gzipped tar file.
#' @param name optional package name, used to provide more informative
#' messages
#' @param subdir subdirectory within url bundle that contains the R package.
#' @param config additional configuration argument (e.g. proxy,
#' authentication) passed on to \code{\link[httr]{GET}}.
#' @param ... Other arguments passed on to \code{\link{install}}.
#' @export
#' @family package installation
install_url <- function(url, name = NULL, subdir = NULL, config = list(), ...) {
if (is.null(name)) {
name <- rep(list(NULL), length(url))
}
invisible(mapply(install_url_single, url, name,
MoreArgs = list(subdir = subdir, config = config, ...)))
}
#' @importFrom httr GET config stop_for_status content
install_url_single <- function(url, name = NULL, subdir = NULL, config = list(), ...) {
if (is.null(name)) {
name <- basename(url)
}
message("Downloading ", name, " from ", url)
bundle <- file.path(tempdir(), name)
# Download package file
request <- GET(url, config)
stop_for_status(request)
writeBin(content(request), bundle)
on.exit(unlink(bundle), add = TRUE)
# Install local file
install_local_single(bundle, subdir = subdir, ...)
}