Open maelle opened 5 years ago
Not really sure if this make what you want, I'm relatively new to R and I'm not sure what inherits and the "{username}" and "{repo}" to pass arguments to functions really do. I try to maintain the format of the function, however at the bottom of the comment is what I would write in my package.
#' Determine whether the repo already exists
#' @param username account name
#' @param repo repo name
#' @details very much inspired by available::available_on_github()
#' @noRd
repo_exists <- function(username, repo) {
check_repo <- function(username, repo) {
# Check repository in the API where all the packages are listed
res <- jsonlite::fromJSON("http://rpkg-api.gepuro.net/rpkg?q={username}/{name}")
# Check exactly that the repository exists on github
any(res$url == "https://github.com/{username}/{name}.git")
}
!inherits(
try(check_repo(
username = username,
repo = repo
),
silent = TRUE
),
"try-error"
)
}
#' Determine whether the repo already exists
#' @param username account name
#' @param repo repo name
#' @details very much inspired by available::available_on_github()
#' @noRd
repo_exists <- function(username, repo) {
# Check repository in the API where all the packages are listed
res <- jsonlite::fromJSON(paste0("http://rpkg-api.gepuro.net/rpkg?q=",username,"/",repo))
# Check exactly that the repository exists on github
any(res$url == "https://github.com/{username}/{name}.git")
}
Hope it helps.
EDIT 1 && 2: sorry, first comment on github and didn't know how to highlight code EDIT 3: Function can be changed easily to give information about if only the username or only the package exists and give an error message saying if the user should change only his/her username or only the name of his/her package
Currently,
repo_exists
will returnFALSE
if there's no repo with the same name for the account... but also if there's something wrong with the API.