Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ Suggests:
rprojroot,
spelling,
testthat (>= 3.0.0),
vctrs,
withr
VignetteBuilder:
knitr
Expand Down
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
14 changes: 14 additions & 0 deletions R/gh_response.R
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,17 @@ gh_process_response <- function(resp, gh_req) {
remove_headers <- function(x) {
x[names(x) != "headers"]
}

# Add vctrs methods that strip attributes from gh_response when combining,
# enabling rectangling via unnesting etc
# See <https://github.com/r-lib/gh/issues/161> 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
}
1 change: 1 addition & 0 deletions inst/WORDLIST
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ pre
programmatically
repo
usethis
wc
2 changes: 1 addition & 1 deletion man/gh-package.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions tests/testthat/test-gh_response.R
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,15 @@ 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", {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

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)
})
Loading