Method for requesting the source details of a package from a user
This commit is contained in:
75
R/request_package_source.R
Normal file
75
R/request_package_source.R
Normal file
@@ -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)
|
||||||
|
}
|
||||||
20
man/request_package_source.Rd
Normal file
20
man/request_package_source.Rd
Normal file
@@ -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
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user