Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extract can_install_dev() #575

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
16 changes: 13 additions & 3 deletions R/install-dev.R
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
#' Install the development version of a package
#'
#' @description
#' `install_dev()` retrieves the package DESCRIPTION from the CRAN mirror and
#' looks in the 'URL' and 'BugReports' fields for GitHub, GitLab or Bitbucket
#' URLs. It then calls the appropriate `install_()` function to install the
#' development package.
#'
#' `can_install_dev()` checks if the development version can be installed.
#'
#' @param package The package name to install.
#' @param cran_url The URL of the CRAN mirror to use, by default based on the
#' 'repos' option. If unset uses 'https://cloud.r-project.org'.
#' @param ... Additional arguments passed to [install_github()],
#' [install_gitlab()], or [install_bitbucket()] functions.
#' @family package installation
#' @export
#' @name install_dev
#' @examples
#' \dontrun{
#' # From GitHub
Expand All @@ -23,7 +27,7 @@
#' # From Bitbucket
#' install_dev("argparser")
#' }
install_dev <- function(package, cran_url = getOption("repos")[["CRAN"]], ...) {
install_dev <- function(package, cran_url = getOption("repos")[["CRAN"]]) {
if (is.null(cran_url) || identical(cran_url, "@CRAN@")) {
cran_url <- "https://cloud.r-project.org"
}
Expand All @@ -40,7 +44,7 @@ install_dev <- function(package, cran_url = getOption("repos")[["CRAN"]], ...) {
url_fields <- c(desc$URL, desc$BugReports)

if (length(url_fields) == 0) {
stop("Could not determine development repository", call. = FALSE)
return(FALSE)
}

pkg_urls <- unlist(strsplit(url_fields, "[[:space:]]*,[[:space:]]*"))
Expand All @@ -64,7 +68,13 @@ install_dev <- function(package, cran_url = getOption("repos")[["CRAN"]], ...) {

parts <- unique(stats::na.omit(parts))

if (nrow(parts) != 1) {
# Can install if we have exactly one valid part
nrow(parts) == 1
}

#' @export
install_dev <- function(package, cran_url = getOption("repos")[["CRAN"]], ...) {
if (!can_install_dev(package, cran_url)) {
stop("Could not determine development repository", call. = FALSE)
}

Expand Down
16 changes: 13 additions & 3 deletions inst/install-github.R

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

16 changes: 13 additions & 3 deletions install-github.R

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

2 changes: 2 additions & 0 deletions man/install_dev.Rd

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