Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@

# Development

* `install_()` functions now pass arguments, including authentication
information and upgrade down to dependencies (#53, #86, #87).

* `install_()` functions now return the name of the package(s) which were
installed (#55).

Expand Down
50 changes: 32 additions & 18 deletions R/deps.R
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ local_package_deps <- function(pkgdir = ".", dependencies = NA) {

dev_package_deps <- function(pkgdir = ".", dependencies = NA,
repos = getOption("repos"),
type = getOption("pkgType")) {
type = getOption("pkgType"), ...) {

pkg <- load_pkg_description(pkgdir)
repos <- c(repos, parse_additional_repositories(pkg))
Expand All @@ -129,7 +129,7 @@ dev_package_deps <- function(pkgdir = ".", dependencies = NA,

combine_deps(
package_deps(deps, repos = repos, type = type),
remote_deps(pkg))
remote_deps(pkg, ...))
}

combine_deps <- function(cran_deps, remote_deps) {
Expand Down Expand Up @@ -280,25 +280,39 @@ update.package_deps <- function(object, ..., quiet = FALSE, upgrade = TRUE) {

install_packages <- function(packages, repos = getOption("repos"),
type = getOption("pkgType"), ...,
dependencies = FALSE, quiet = NULL,
# These are options to `install()` used when
# installing remotes, but can get passed to us by
# `...` so we just ignore them here
build, build_opts) {
dependencies = FALSE, quiet = NULL) {

# We want to pass only args that exist in the downstream functions
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't really love this, but I am not sure of a better way to do it, you could list even more arguments here to catch them, but that seems like it would be a pain to maintain as the possible number of arguments in the install_() functions increases.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it would be nice to have some "centralized" solution for this. But it will do here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we required that all install functions take ... and then use ellipsis to warn if an argument is never evaluated?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remotes does not have dependencies, by design. ellipsis already has compiled code, and will trigger the DLL locking issue on Windows.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, oops, I forgot about that constraint.

args_to_keep <-
unique(
names(
c(
formals(install.packages),
formals(download.file)
)
)
)

args <- list(...)
args <- args[names(args) %in% args_to_keep]

if (is.null(quiet))
quiet <- !identical(type, "source")

message("Installing ", length(packages), " packages: ",
paste(packages, collapse = ", "))

safe_install_packages(
packages,
repos = repos,
type = type,
...,
dependencies = dependencies,
quiet = quiet
do.call(
safe_install_packages,
c(list(
packages,
repos = repos,
type = type,
dependencies = dependencies,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to translate dependencies = TRUE to dependencies = NA to avoid installing all suggested dependencies of dependencies?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Based on an empirical test, this works fine, at least install_github("r-lib/processx", dependencies = TRUE) only installs Suggests for processx.

quiet = quiet
),
args
)
)
}

Expand Down Expand Up @@ -381,7 +395,7 @@ fix_repositories <- function(repos) {
repos
}

parse_one_remote <- function(x) {
parse_one_remote <- function(x, ...) {
pieces <- strsplit(x, "::", fixed = TRUE)[[1]]

if (length(pieces) == 1) {
Expand All @@ -397,7 +411,7 @@ parse_one_remote <- function(x) {
fun <- get(paste0(tolower(type), "_remote"),
envir = asNamespace("remotes"), mode = "function", inherits = FALSE)

res <- fun(repo)
res <- fun(repo, ...)
}, error = function(e) stop("Unknown remote type: ", type, "\n ", conditionMessage(e), call. = FALSE)
)
res
Expand All @@ -412,13 +426,13 @@ split_remotes <- function(x) {
}


remote_deps <- function(pkg) {
remote_deps <- function(pkg, ...) {
if (!has_dev_remotes(pkg)) {
return(NULL)
}

dev_packages <- split_remotes(pkg[["remotes"]])
remote <- lapply(dev_packages, parse_one_remote)
remote <- lapply(dev_packages, parse_one_remote, ...)

package <- vapply(remote, remote_package_name, character(1), USE.NAMES = FALSE)
installed <- vapply(package, local_sha, character(1), USE.NAMES = FALSE)
Expand Down
14 changes: 7 additions & 7 deletions R/install-bioc.R
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,20 @@
install_bioc <- function(repo, mirror = getOption("BioC_git", download_url("git.bioconductor.org/packages")),
git = c("auto", "git2r", "external"), ...) {

bioc_remote <- select_bioc_git_remote(match.arg(git))

remotes <- lapply(repo, bioc_remote, mirror = mirror)
remotes <- lapply(repo, bioc_remote, mirror = mirror, git = match.arg(git))

install_remotes(remotes, ...)
}

select_bioc_git_remote <- function(git) {
bioc_remote <- function(repo, mirror = getOption("BioC_git", download_url("git.bioconductor.org/packages")),
git = c("auto", "git2r", "external"), ...) {

git <- match.arg(git)
if (git == "auto") {
git <- if (pkg_installed("git2r")) "git2r" else "external"
}
switch(git,
git2r = bioc_git2r_remote,
external = bioc_xgit_remote)

list(git2r = bioc_git2r_remote, external = bioc_xgit_remote)[[git]](repo, mirror)
}

# Parse concise git repo specification: [username:password@][branch/]repo[#commit]
Expand Down
6 changes: 3 additions & 3 deletions R/install-bitbucket.R
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ install_bitbucket <- function(repo, ref = "master", subdir = NULL,
remotes <- lapply(repo, bitbucket_remote, ref = ref,
subdir = subdir, auth_user = auth_user, password = password, host = host)

install_remotes(remotes, ...)
install_remotes(remotes, auth_user = auth_user, password = password, host = host, ...)
}

bitbucket_remote <- function(repo, ref = NULL, subdir = NULL,
bitbucket_remote <- function(repo, ref = "master", subdir = NULL,
auth_user = NULL, password = NULL, sha = NULL,
host = NULL) {
host = NULL, ...) {

meta <- parse_git_repo(repo)

Expand Down
2 changes: 1 addition & 1 deletion R/install-cran.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ install_cran <- function(pkgs, repos = getOption("repos"), type = getOption("pkg
install_remotes(remotes, quiet = quiet, ...)
}

cran_remote <- function(pkg, repos, type) {
cran_remote <- function(pkg, repos, type, ...) {

remote("cran",
name = pkg,
Expand Down
2 changes: 1 addition & 1 deletion R/install-git.R
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ install_git <- function(url, subdir = NULL, branch = NULL,
}


git_remote <- function(url, subdir = NULL, branch = NULL, git = c("auto", "git2r", "external")) {
git_remote <- function(url, subdir = NULL, branch = NULL, git = c("auto", "git2r", "external"), ...) {
git <- match.arg(git)
if (git == "auto") {
git <- if (pkg_installed("git2r")) "git2r" else "external"
Expand Down
6 changes: 3 additions & 3 deletions R/install-github.R
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@ install_github <- function(repo,
remotes <- lapply(repo, github_remote, ref = ref,
subdir = subdir, auth_token = auth_token, host = host)

install_remotes(remotes, ...)
install_remotes(remotes, auth_token = auth_token, host = host, ...)
}

github_remote <- function(repo, ref = NULL, subdir = NULL,
github_remote <- function(repo, ref = "master", subdir = NULL,
auth_token = github_pat(), sha = NULL,
host = "api.github.com") {
host = "api.github.com", ...) {

meta <- parse_git_repo(repo)
meta <- github_resolve_ref(meta$ref %||% ref, meta, auth_token)
Expand Down
4 changes: 2 additions & 2 deletions R/install-gitlab.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ install_gitlab <- function(repo,

remotes <- lapply(repo, gitlab_remote, auth_token = auth_token, host = host)

install_remotes(remotes, ...)
install_remotes(remotes, auth_token = auth_token, host = host, ...)
}

gitlab_remote <- function(repo,
auth_token = gitlab_pat(), sha = NULL,
host = "gitlab.com") {
host = "gitlab.com", ...) {

meta <- parse_git_repo(repo)
meta$ref <- meta$ref %||% "master"
Expand Down
2 changes: 1 addition & 1 deletion R/install-local.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ install_local <- function(path, subdir = NULL, ...) {
install_remotes(remotes, ...)
}

local_remote <- function(path, subdir = NULL, branch = NULL, args = character(0)) {
local_remote <- function(path, subdir = NULL, branch = NULL, args = character(0), ...) {
remote("local",
path = normalizePath(path),
subdir = subdir
Expand Down
4 changes: 2 additions & 2 deletions R/install-svn.R
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ install_svn <- function(url, subdir = NULL, args = character(0),
remotes <- lapply(url, svn_remote, svn_subdir = subdir,
revision = revision, args = args)

install_remotes(remotes, ...)
install_remotes(remotes, args = args, ...)
}

svn_remote <- function(url, svn_subdir = NULL, revision = NULL,
args = character(0)) {
args = character(0), ...) {
remote("svn",
url = url,
svn_subdir = svn_subdir,
Expand Down
2 changes: 1 addition & 1 deletion R/install-url.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ install_url <- function(url, subdir = NULL, ...) {
install_remotes(remotes, ...)
}

url_remote <- function(url, subdir = NULL) {
url_remote <- function(url, subdir = NULL, ...) {
remote("url",
url = url,
subdir = subdir
Expand Down
13 changes: 10 additions & 3 deletions R/install.R
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ safe_build_package <- function(pkgdir, build_opts, dest_path, quiet, use_pkgbuil
#' @param threads Number of threads to start, passed to
#' \code{\link[utils]{install.packages}} as \code{Ncpus}.
#' @param ... additional arguments passed to \code{\link[utils]{install.packages}}.
#' @param build If \code{TRUE} build the pacakge before installing.
#' @param build_opts Options to pass to `R CMD build`.
#' @export
#' @examples
#' \dontrun{install_deps(".")}
Expand All @@ -109,13 +111,16 @@ install_deps <- function(pkgdir = ".", dependencies = NA,
type = getOption("pkgType"),
...,
upgrade = TRUE,
quiet = FALSE) {
quiet = FALSE,
build = TRUE,
build_opts = c("--no-resave-data", "--no-manual", "--no-build-vignettes")) {

packages <- dev_package_deps(
pkgdir,
repos = repos,
dependencies = dependencies,
type = type
type = type,
...
)

dep_deps <- if (isTRUE(dependencies)) NA else dependencies
Expand All @@ -126,6 +131,8 @@ install_deps <- function(pkgdir = ".", dependencies = NA,
...,
Ncpus = threads,
quiet = quiet,
upgrade = upgrade
upgrade = upgrade,
build = build,
build_opts = build_opts
)
}
8 changes: 7 additions & 1 deletion man/install_deps.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions man/package_deps.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.