remotes
remotes copied to clipboard
Generic install_remote to accept non specific remote
I have been fiddling with a way to take in a bunch of strings as specified by the same format as Remotes in a description file, along with default CRAN installations. For instance for a vector like
packages = c('r-lib/remotes','bioc::3.6/affy','ggplot2')
I want to be able to call a single function
install_remotes(packages)
To install them all.
The way I came up with by wandering within the functions here appears to be more complicated than it should be as the default inputs to the internal functions seems to be package paths in most cases.
install_remotes = function(x,quiet = FALSE , upgrade = 'default',build = TRUE,build_opts = '--no-resave-data'){
isRemote = grepl('::|/',x)
remotes = x[isRemote]
remote = remotes %>% lapply(remotes:::parse_one_remote)
package <- vapply(remote, function(x) remotes:::remote_package_name(x),
character(1), USE.NAMES = FALSE)
installed <- vapply(package, function(x) remotes:::local_sha(x), character(1),
USE.NAMES = FALSE)
available <- vapply(remote, function(x) remotes:::remote_sha(x), character(1),
USE.NAMES = FALSE)
diff <- installed == available
diff <- ifelse(!is.na(diff) & diff, remotes:::CURRENT, remotes:::BEHIND)
diff[is.na(installed)] <- remotes:::UNINSTALLED
remote_packages <- structure(data.frame(package = package, installed = installed,
available = available, diff = diff, is_cran = FALSE,
stringsAsFactors = FALSE), class = c("package_deps",
"data.frame"))
remote_packages$remote <- structure(remote, class = "remotes")
CRANs = x[!isRemote]
CRANs = package_deps(CRANs, repos = getOption("repos"),type = getOption("pkgType"),dependencies = NA)
# toUpdate = remotes:::combine_deps(CRANs,remote_packages)
toUpdate = rbind(CRANs, remote_packages)
# dep_deps <- if (isTRUE(dependencies))
# NA
# else dependencies
update(toUpdate, dependencies = NA, quiet = quiet,
upgrade = upgrade, build = build, build_opts = build_opts)
}
install_remotes(c('r-lib/remotes','bioc::3.6/affy','ggplot2'))
I am not that familiar with the package internals so I am unsure if there is a better way to do this or if this is quite correct (it seems to work though the use of package_deps for CRAN packages seem counter intuitive, that part is copied from dev_package_deps).
I would like to know if there is a properly supported way to do this without resorting to package internals and could use recommendations on my version.
I think something like this would do what you want.
install_remotes2 <- function(x,
dependencies = NA,
upgrade = c("default", "ask", "always", "never"),
force = FALSE,
quiet = FALSE,
build = TRUE, build_opts = c("--no-resave-data", "--no-manual", "--no-build-vignettes"),
build_manual = FALSE, build_vignettes = FALSE,
repos = getOption("repos"),
type = getOption("pkgType"),
...) {
# add cran:: to bare package names
is_remote <- grepl("::|/", x)
x[!is_remote] <- paste0("cran::", x[!is_remote])
remotes <- lapply(x, remotes:::parse_one_remote, repos = repos, type = type)
remotes:::install_remotes(remotes, dependencies = dependencies,
upgrade = upgrade, force = force, quiet = quiet,
build = build, build_opts = build_opts,
build_manual = build_manual, build_vignettes = build_vignettes,
repos = repos, type = type, ...)
}
install_remotes2(c('r-lib/remotes','bioc::3.6/affy','ggplot2'))
It looks like this solution broke relatively recently with the removal of remotes:::parse_one_remote trying to find what the replacement to it is
@oganm pak::pkg_install() is preferred replacement for installing a package from any package source.
ah beautiful thank you