Skip to content

Commit

Permalink
provide as_tibble as an alternative to collect. Closes #166 (#189)
Browse files Browse the repository at this point in the history
  • Loading branch information
boshek authored Apr 24, 2020
1 parent 0a7b25d commit 6f86247
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 2 deletions.
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Generated by roxygen2: do not edit by hand

S3method(as_tibble,bcdc_promise)
S3method(bcdc_describe_feature,bcdc_record)
S3method(bcdc_describe_feature,character)
S3method(bcdc_describe_feature,default)
Expand Down Expand Up @@ -66,6 +67,7 @@ importFrom(cli,col_blue)
importFrom(cli,col_green)
importFrom(cli,col_red)
importFrom(dplyr,"%>%")
importFrom(dplyr,as_tibble)
importFrom(dplyr,collect)
importFrom(dplyr,filter)
importFrom(dplyr,mutate)
Expand Down
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* Rename `selectable` column from `bcdc_describe_feature` to `sticky` and modify corresponding docs and tests (#180)
* Fix `select`, `filter` and `mutate` roxygen so that bcdata specific documentation to these methods is available
* Add `head` and `tail` methods for `bcdc.promise` objects. Thanks to @hgriesbauer for the suggestion! (#182, #186)
* Provide `as_tibble` as an alias for `collect` in line with `dbplyr` behaviour (#166)

# bcdata 0.1.2

Expand Down
12 changes: 11 additions & 1 deletion R/utils-classes.R
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,8 @@ mutate.bcdc_promise <- function(.data, ...){
#' Force collection of Web Service request from B.C. Data Catalogue
#'
#' After tuning a query, `collect()` is used to actually bring the data into memory.
#' This will retrieve an sf object into R.
#' This will retrieve an sf object into R. The `as_tibble` can be used interchangeably
#' with `collect` which matches `dbplyr` behaviour.
#'
#' @param x object of class bcdc_promise
#' @inheritParams collect
Expand All @@ -321,6 +322,9 @@ mutate.bcdc_promise <- function(.data, ...){
#' \donttest{
#' bcdc_query_geodata("bc-airports") %>%
#' collect()
#'
#' bcdc_query_geodata("bc-airports") %>%
#' as_tibble()
#' }
#'
collect.bcdc_promise <- function(x, ...){
Expand Down Expand Up @@ -384,6 +388,12 @@ collect.bcdc_promise <- function(x, ...){

}


#' @describeIn collect as_tibble.bcdc_promise
#' @importFrom dplyr as_tibble
#' @export
as_tibble.bcdc_promise <- collect.bcdc_promise

#' Show SQL and URL used for Web Service request from B.C. Data Catalogue
#'
#' Display Web Service query SQL
Expand Down
11 changes: 10 additions & 1 deletion man/collect.Rd

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

8 changes: 8 additions & 0 deletions tests/testthat/test-query-geodata-collect.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ test_that("bcdc_query_geodata collects an sf object for a valid id", {
expect_equal(attr(bc_airports, "sf_column"), "geometry")
})

test_that("bcdc_query_geodata collects using as_tibble", {
skip_on_cran()
skip_if_net_down()
bc_airports <- bcdc_query_geodata("bc-airports") %>% as_tibble()
expect_is(bc_airports, "sf")
expect_equal(attr(bc_airports, "sf_column"), "geometry")
})

test_that("bcdc_query_geodata succeeds with a records over 10000 rows",{
skip_on_cran()
skip("Skipping the BEC test, though available for testing")
Expand Down

0 comments on commit 6f86247

Please sign in to comment.