diff --git a/DESCRIPTION b/DESCRIPTION index c830377..0dd1685 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: gh Title: 'GitHub' 'API' -Version: 1.4.1.9000 +Version: 1.4.1.9001 Authors@R: c( person("Gábor", "Csárdi", , "csardi.gabor@gmail.com", role = c("cre", "ctb")), person("Jennifer", "Bryan", role = "aut"), @@ -29,6 +29,7 @@ Suggests: rprojroot, spelling, testthat (>= 3.0.0), + vctrs, withr VignetteBuilder: knitr @@ -37,4 +38,4 @@ Config/testthat/edition: 3 Encoding: UTF-8 Language: en-US Roxygen: list(markdown = TRUE) -RoxygenNote: 7.3.1.9000 +RoxygenNote: 7.3.2 diff --git a/NAMESPACE b/NAMESPACE index bc79b8e..e0eefc3 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -4,6 +4,8 @@ S3method(format,gh_pat) S3method(print,gh_pat) S3method(print,gh_response) S3method(str,gh_pat) +S3method(vctrs::vec_cast,list.gh_response) +S3method(vctrs::vec_ptype2,gh_response.gh_response) export(gh) export(gh_first) export(gh_gql) diff --git a/NEWS.md b/NEWS.md index e3191de..f648213 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,8 +1,10 @@ # gh (development version) +* `gh_response` class now works more nicely with tidyr rectangling (@tanho63, #161) * `gh()` now uses a cache provided by httr2. This cache lives in `tools::R_user_dir("gh", "cache")`, maxes out at 100 MB, and can be disabled by setting `options(gh_cache = FALSE)` (#203). * Removes usage of mockery (@tanho63, #197) + # gh 1.4.1 * `gh_next()`, `gh_prev()`, `gh_first()` and `gh_last()` diff --git a/R/gh_response.R b/R/gh_response.R index a9d47e9..fd5638e 100644 --- a/R/gh_response.R +++ b/R/gh_response.R @@ -42,3 +42,17 @@ gh_process_response <- function(resp, gh_req) { } res } + +# Add vctrs methods that strip attributes from gh_response when combining, +# enabling rectangling via unnesting etc +# See for more details +#' @exportS3Method vctrs::vec_ptype2 +vec_ptype2.gh_response.gh_response <- function(x, y, ...) { + list() +} + +#' @exportS3Method vctrs::vec_cast +vec_cast.list.gh_response <- function(x, to, ...) { + attributes(x) <- NULL + x +} diff --git a/inst/WORDLIST b/inst/WORDLIST index 4fb08fa..e2305b8 100644 --- a/inst/WORDLIST +++ b/inst/WORDLIST @@ -19,5 +19,8 @@ keyring macOS pre programmatically +rectangling repo +tidyr usethis +vctrs diff --git a/tests/testthat/test-gh_response.R b/tests/testthat/test-gh_response.R index 6ae8c0d..633132c 100644 --- a/tests/testthat/test-gh_response.R +++ b/tests/testthat/test-gh_response.R @@ -83,3 +83,14 @@ test_that("output file is not overwritten on error", { expect_equal(readLines(tmp), "foo") expect_true(!is.null((err$response_content))) }) + +test_that("gh_response objects can be combined via vctrs #161",{ + skip_on_cran() + skip_if_not_installed("vctrs") + user_1 <- gh("/users", .limit = 1) + user_2 <- gh("/users", .limit = 1,) + user_vec <- vctrs::vec_c(user_1, user_2) + user_df <- vctrs::vec_rbind(user_1[[1]], user_2[[1]]) + expect_equal(length(user_vec), 2) + expect_equal(nrow(user_df), 2) +})