Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add vctrs methods to make rectangling nicer #201

Closed
wants to merge 9 commits into from
Closed
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
5 changes: 3 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -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"),
Expand Down Expand Up @@ -29,6 +29,7 @@ Suggests:
rprojroot,
spelling,
testthat (>= 3.0.0),
vctrs,
withr
VignetteBuilder:
knitr
Expand All @@ -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
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
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -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()`
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) {
}
res
}

# 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
}
3 changes: 3 additions & 0 deletions inst/WORDLIST
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,8 @@ keyring
macOS
pre
programmatically
rectangling
repo
tidyr
usethis
vctrs
11 changes: 11 additions & 0 deletions tests/testthat/test-gh_response.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
tanho63 marked this conversation as resolved.
Show resolved Hide resolved
})
Loading