From a6ee51b9fb20590498e8f857ba175cac35dd1dcd Mon Sep 17 00:00:00 2001 From: Rick Tankard Date: Sun, 4 Sep 2022 18:18:24 +1000 Subject: [PATCH 1/4] Added github_locations() and documented it Documentation on same page as available_on_github(). --- NAMESPACE | 1 + R/github.R | 20 ++++++++++++++++++++ man/available_on_github.Rd | 9 +++++++++ 3 files changed, 30 insertions(+) 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..a599672 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,15 @@ 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'.") + } + 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) { 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) +} From e097ddd3ac2ce61e6b84e83ddfc6e2d2b1c7bb3f Mon Sep 17 00:00:00 2001 From: Rick Tankard Date: Sun, 4 Sep 2022 18:21:45 +1000 Subject: [PATCH 2/4] Report on number of repositories --- R/github.R | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/R/github.R b/R/github.R index a599672..ff3fabc 100644 --- a/R/github.R +++ b/R/github.R @@ -62,7 +62,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 From b9ee3a60d99e2c1b60bd3ae3ad278bef50dfd0d8 Mon Sep 17 00:00:00 2001 From: Rick Tankard Date: Sun, 4 Sep 2022 18:28:04 +1000 Subject: [PATCH 3/4] github_locations gives vector of length 0 when appropriate --- R/github.R | 3 +++ tests/testthat/test-github.R | 6 ++++++ 2 files changed, 9 insertions(+) diff --git a/R/github.R b/R/github.R index ff3fabc..57235e6 100644 --- a/R/github.R +++ b/R/github.R @@ -45,6 +45,9 @@ 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"]] } diff --git a/tests/testthat/test-github.R b/tests/testthat/test-github.R index 4601d5f..1186b3d 100644 --- a/tests/testthat/test-github.R +++ b/tests/testthat/test-github.R @@ -11,3 +11,9 @@ test_that("Can't find made up package", { expect_true(available_on_github("This_is_not_a_pkg")$available) }) + +test_that("github_locations() gives empty vector when there are no results", { + skip_on_cran() + + expect_equal(github_locations(available_on_github("This_is_not_a_pkg")), character(0)) +}) From 085c056fdcde6ec7313f6edef649704cd40dffc1 Mon Sep 17 00:00:00 2001 From: Rick Tankard Date: Sun, 4 Sep 2022 18:32:05 +1000 Subject: [PATCH 4/4] tests for incorrect input to github_locations() --- tests/testthat/test-github.R | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/testthat/test-github.R b/tests/testthat/test-github.R index 1186b3d..d50b0c7 100644 --- a/tests/testthat/test-github.R +++ b/tests/testthat/test-github.R @@ -12,8 +12,9 @@ test_that("Can't find made up package", { expect_true(available_on_github("This_is_not_a_pkg")$available) }) -test_that("github_locations() gives empty vector when there are no results", { +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'") })