From 903f5cf365a21413d696f50d66de2b82e7888c21 Mon Sep 17 00:00:00 2001 From: Craig Williams Date: Thu, 16 Jun 2022 11:42:27 +0100 Subject: [PATCH] Method for requesting the source details of a package from a user --- R/request_package_source.R | 75 +++++++++++++++++++++++++++++++++++ man/request_package_source.Rd | 20 ++++++++++ 2 files changed, 95 insertions(+) create mode 100644 R/request_package_source.R create mode 100644 man/request_package_source.Rd diff --git a/R/request_package_source.R b/R/request_package_source.R new file mode 100644 index 0000000..3d4c7a4 --- /dev/null +++ b/R/request_package_source.R @@ -0,0 +1,75 @@ +# Requires utils.R + +#' Method for requesting a non-CRAN package source from a user +#' +#' @param package string The name of the package +#' +#' @return invisible NULL on cancel +#' @return List containing the type of the source, the source URI and an +#' optional reference +request_package_source <- function(package) { + source <- NULL + repeat { + type <- select_menu( + c("git_url", "github", "gitlab", "svn", "bitbucket", "Bioconductor", "Cancel"), + msg = "How would you like to source the package (default: git_url): ", + default = 1 + )[[1]] + if (type == "Cancel") { + return(invisible(NULL)) + } + + repeat { + src <- trimws(readline("Please specify the source for the package: ")) + if (nchar(src) > 0) { + break + } + } + + ref <- NULL + if (type %in% c("git_url", "github", "bitbucket")) { + ref <- trimws(readline( + "Please specify a reference (tag/commit/branch/default=HEAD) for the package: " + )) + if (nchar(ref) == 0) { + ref <- "HEAD" + } + } + if (type %in% c("svn")) { + ref <- trimws(readline("Please specify a revision (default=HEAD) for the package: ")) + if (nchar(ref) == 0) { + ref <- NULL + } + } + + new_remote <- switch( + type, + git_url = remotes:::git_remote(src, ref = ref), + github = remotes:::github_remote(src, ref = ref), + gitlab = remotes:::gitlab_remote(src), + svn = remotes:::svn_remote(src, revision = ref), + bitbucket = remotes:::bitbucket_remote(src, ref = ref), + Bioconductor = remotes:::bio_remote(src) + ) + res <- try( + { + bundle <- remotes:::remote_download(new_remote, quiet = TRUE) + }, + silent = TRUE + ) + if (inherits(res, "try-error")) { + cat("Unabled to access source, please try again.") + next + } + unlink(bundle) + + source <- list( + type = type, + src = src, + ref = ref + ) + break + } + + return(source) +} diff --git a/man/request_package_source.Rd b/man/request_package_source.Rd new file mode 100644 index 0000000..429ab4a --- /dev/null +++ b/man/request_package_source.Rd @@ -0,0 +1,20 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/request_package_source.R +\name{request_package_source} +\alias{request_package_source} +\title{Method for requesting a non-CRAN package source from a user} +\usage{ +request_package_source(package) +} +\arguments{ +\item{package}{string The name of the package} +} +\value{ +invisible NULL on cancel + +List containing the type of the source, the source URI and an + optional reference +} +\description{ +Method for requesting a non-CRAN package source from a user +}