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

create paginated only print msg #264

Merged
merged 6 commits into from
Apr 13, 2021
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
11 changes: 9 additions & 2 deletions R/utils-classes.R
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,11 @@ print.bcdc_promise <- function(x, ...) {

catch_wfs_error(cc)

## pagination printing
number_of_records <- bcdc_number_wfs_records(x$query_list, x$cli)
sdl <- getOption("bcdata.single_download_limit", default = bcdc_single_download_limit())
cl <- getOption("bcdata.chunk_limit", default = 1000)
paginate <- number_of_records > sdl

if (!is.null(x$query_list$count)) {
# head or tail have updated the count
Expand All @@ -69,6 +73,8 @@ print.bcdc_promise <- function(x, ...) {

cat_bullet(strwrap(glue::glue("Using {col_blue('collect()')} on this object will return {col_green(number_of_records)} features ",
"and {col_green(fields)} fields")))
if (paginate) cat_bullet(strwrap(glue::glue("Accessing this record requires pagination and will make {col_green(ceiling(number_of_records/cl))} separate requests to the WFS. ",
"See ?bcdc_options")))
cat_bullet(strwrap("At most six rows of the record are printed here"))
cat_rule()
print(parsed)
Expand Down Expand Up @@ -389,7 +395,8 @@ collect.bcdc_promise <- function(x, ...){
url <- cc$url
full_url <- cli$url_fetch(query = query_list)
} else {
message("This record requires pagination to complete the request.")
chunk <- getOption("bcdata.chunk_limit", default = 1000)
message(glue::glue("This object has {number_of_records} records and requires {ceiling(number_of_records/chunk)} paginated requests to complete."))
sorting_col <- pagination_sort_col(x$cols_df)

query_list <- c(query_list, sortby = sorting_col)
Expand All @@ -401,7 +408,7 @@ collect.bcdc_promise <- function(x, ...){
limit_param = "count",
offset_param = "startIndex",
limit = number_of_records,
chunk = getOption("bcdata.chunk_limit", default = 1000),
chunk = chunk,
progress = interactive()
)

Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-options.R
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ test_that("bcdata.single_download_limit", {
expect_message(
bcdc_get_data(record = '76b1b7a3-2112-4444-857a-afccf7b20da8', resource =
'4d0377d9-e8a1-429b-824f-0ce8f363512c'),
"pagination"
"paginated"
)

})
Expand Down