diff --git a/NAMESPACE b/NAMESPACE index 6941c83..e583a3b 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -25,6 +25,7 @@ export(get_bad_words) export(get_sentiment) export(get_wikipedia) export(get_wiktionary) +export(github_locations) export(suggest) export(valid_package_name) importFrom(jsonlite,fromJSON) diff --git a/R/github.R b/R/github.R index dec7a2d..57235e6 100644 --- a/R/github.R +++ b/R/github.R @@ -1,6 +1,17 @@ #' See if a name is available on github #' +#' @rdname available_on_github +#' @name available_on_github +#' @aliases github_locations +#' #' @param name Name of package to search +#' @param x An object from available_on_github() +#' @examples +#' x <- available_on_github("available") +#' github_locations(x) +NULL + +#' @rdname available_on_github #' @importFrom jsonlite fromJSON #' @export available_on_github <- function(name) { @@ -28,6 +39,18 @@ available_on_github <- function(name) { class = "available_github") } +#' @rdname available_on_github +#' @export +github_locations <- function(x) { + if(!inherits(x, "available_github")) { + stop("x is not an object of class 'available_github'.") + } + if(isTRUE(x$available)) { + return(character()) + } + x$close[[1]][["pkg_location"]] +} + gh_pkg <- memoise::memoise(function(pkg) { res <- jsonlite::fromJSON(paste0("http://rpkg-api.gepuro.net/rpkg?q=", pkg)) if (length(res) == 0) { @@ -42,7 +65,12 @@ gh_pkg <- memoise::memoise(function(pkg) { #' @export format.available_github <- function(x, ...) { - paste0(crayon::bold("Available on GitHub: ", yes_no(x[[1]]), "\n")) + if(isTRUE(x[[1]])) { + report <- "" + } else { + report <- paste(nrow(x$close[[1]]), "repositories") + } + paste0(crayon::bold("Available on GitHub: ", yes_no(x[[1]]), report, "\n")) } #' @export diff --git a/man/available_on_github.Rd b/man/available_on_github.Rd index 5eb806a..bf9b019 100644 --- a/man/available_on_github.Rd +++ b/man/available_on_github.Rd @@ -2,13 +2,22 @@ % Please edit documentation in R/github.R \name{available_on_github} \alias{available_on_github} +\alias{github_locations} \title{See if a name is available on github} \usage{ available_on_github(name) + +github_locations(x) } \arguments{ \item{name}{Name of package to search} + +\item{x}{An object from available_on_github()} } \description{ See if a name is available on github } +\examples{ +x <- available_on_github("available") +github_locations(x) +} diff --git a/tests/testthat/test-github.R b/tests/testthat/test-github.R index 4601d5f..d50b0c7 100644 --- a/tests/testthat/test-github.R +++ b/tests/testthat/test-github.R @@ -11,3 +11,10 @@ test_that("Can't find made up package", { expect_true(available_on_github("This_is_not_a_pkg")$available) }) + +test_that("github_locations() tests", { + skip_on_cran() + + expect_equal(github_locations(available_on_github("This_is_not_a_pkg")), character(0)) + expect_error(github_locations(5), "of class 'available_github'") +})