From 0aa7136439207c5119868fcd44e0d7f82a3e5eba Mon Sep 17 00:00:00 2001 From: Tan Ho Date: Thu, 15 Aug 2024 11:28:22 -0700 Subject: [PATCH 1/7] add vctrs methods to make rectangling nicer --- DESCRIPTION | 3 ++- NAMESPACE | 2 ++ R/gh_response.R | 14 ++++++++++++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index c86efc3..185a46f 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -30,6 +30,7 @@ Suggests: rprojroot, spelling, testthat (>= 3.0.0), + vctrs, withr VignetteBuilder: knitr @@ -38,4 +39,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/R/gh_response.R b/R/gh_response.R index 7943f1b..c25db5f 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 +} From e85041f3b913d4d4414e5cafad2989eb3eb8d063 Mon Sep 17 00:00:00 2001 From: Tan Ho Date: Thu, 15 Aug 2024 11:28:59 -0700 Subject: [PATCH 2/7] bump version --- DESCRIPTION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index 185a46f..b68861b 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"), From 6719f76f4e31b1c52c14e2dd325beb17e4ee6b79 Mon Sep 17 00:00:00 2001 From: Tan Ho Date: Thu, 15 Aug 2024 11:33:23 -0700 Subject: [PATCH 3/7] news update --- NEWS.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/NEWS.md b/NEWS.md index 6cf7fbd..b9e3113 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,7 @@ # gh (development version) +* `gh_response` class now works more nicely with tidyr rectangling (#161) + # gh 1.4.1 * `gh_next()`, `gh_prev()`, `gh_first()` and `gh_last()` From 3c167b868461237a32c8b0ce8a8a6e8981fa8dd3 Mon Sep 17 00:00:00 2001 From: Tan Ho <38083823+tanho63@users.noreply.github.com> Date: Thu, 15 Aug 2024 11:42:02 -0700 Subject: [PATCH 4/7] Update WORDLIST --- inst/WORDLIST | 3 +++ 1 file changed, 3 insertions(+) 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 From bb14b090d2ad37a8091b48602d7c8fdff52e5583 Mon Sep 17 00:00:00 2001 From: Tan Ho <38083823+tanho63@users.noreply.github.com> Date: Thu, 15 Aug 2024 13:12:04 -0700 Subject: [PATCH 5/7] Update NEWS.md --- NEWS.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NEWS.md b/NEWS.md index b9e3113..27b9283 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,6 +1,6 @@ # gh (development version) -* `gh_response` class now works more nicely with tidyr rectangling (#161) +* `gh_response` class now works more nicely with tidyr rectangling (@tanho63, #161) # gh 1.4.1 From b265963730101dce0e440f6a5ae66231350d0033 Mon Sep 17 00:00:00 2001 From: Tan Date: Tue, 20 Aug 2024 17:18:31 -0400 Subject: [PATCH 6/7] add tests --- tests/testthat/test-gh_response.R | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tests/testthat/test-gh_response.R b/tests/testthat/test-gh_response.R index 6ae8c0d..b5d181d 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_vec), 2) +}) From 2d687edd1a55044839640b54323e86cf7f598428 Mon Sep 17 00:00:00 2001 From: Tan Date: Tue, 20 Aug 2024 17:21:23 -0400 Subject: [PATCH 7/7] whoops --- tests/testthat/test-gh_response.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/testthat/test-gh_response.R b/tests/testthat/test-gh_response.R index b5d181d..633132c 100644 --- a/tests/testthat/test-gh_response.R +++ b/tests/testthat/test-gh_response.R @@ -92,5 +92,5 @@ test_that("gh_response objects can be combined via vctrs #161",{ 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_vec), 2) + expect_equal(nrow(user_df), 2) })