diff --git a/R/install-dev.R b/R/install-dev.R index 18b2adc0..c0106a11 100644 --- a/R/install-dev.R +++ b/R/install-dev.R @@ -1,10 +1,13 @@ #' 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'. @@ -12,6 +15,7 @@ #' [install_gitlab()], or [install_bitbucket()] functions. #' @family package installation #' @export +#' @name install_dev #' @examples #' \dontrun{ #' # From GitHub @@ -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" } @@ -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:]]*")) @@ -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) } diff --git a/inst/install-github.R b/inst/install-github.R index ee08f07a..09ee7881 100644 --- a/inst/install-github.R +++ b/inst/install-github.R @@ -2497,11 +2497,14 @@ function(...) { # Contents of R/install-dev.R #' 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'. @@ -2509,6 +2512,7 @@ function(...) { #' [install_gitlab()], or [install_bitbucket()] functions. #' @family package installation #' @export + #' @name install_dev #' @examples #' \dontrun{ #' # From GitHub @@ -2520,7 +2524,7 @@ function(...) { #' # 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" } @@ -2537,7 +2541,7 @@ function(...) { 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:]]*")) @@ -2561,7 +2565,13 @@ function(...) { 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) } diff --git a/install-github.R b/install-github.R index ee08f07a..09ee7881 100644 --- a/install-github.R +++ b/install-github.R @@ -2497,11 +2497,14 @@ function(...) { # Contents of R/install-dev.R #' 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'. @@ -2509,6 +2512,7 @@ function(...) { #' [install_gitlab()], or [install_bitbucket()] functions. #' @family package installation #' @export + #' @name install_dev #' @examples #' \dontrun{ #' # From GitHub @@ -2520,7 +2524,7 @@ function(...) { #' # 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" } @@ -2537,7 +2541,7 @@ function(...) { 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:]]*")) @@ -2561,7 +2565,13 @@ function(...) { 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) } diff --git a/man/install_dev.Rd b/man/install_dev.Rd index bd7ccbe3..80f12e04 100644 --- a/man/install_dev.Rd +++ b/man/install_dev.Rd @@ -20,6 +20,8 @@ install_dev(package, cran_url = getOption("repos")[["CRAN"]], ...) looks in the 'URL' and 'BugReports' fields for GitHub, GitLab or Bitbucket URLs. It then calls the appropriate \code{install_()} function to install the development package. + +\code{can_install_dev()} checks if the development version can be installed. } \examples{ \dontrun{