canpaginate

knitr::opts_chunk$set(
  comment = "#>",
  collapse = TRUE,
  warning = FALSE,
  message = FALSE
)

Project Status: WIP – Initial development is in progress, but there has not yet been a stable, usable release suitable for the public. Build Status

canpaginate helps you paginate with REST APIs

(p.s. named inspired from Ruby's will_paginate, though this pkgs focus is slightly diff. from that of will_paginate)

Why? The problems:

install

devtools::install_github("ropensci/canpaginate")
library(canpaginate)

Set pagination options

query parameters

x <- can_paginate(
  by = "query_params",
  limit_param = "limit",
  offset_param = "offset",
  limit = 5000
)
x$by

link headers

x <- can_paginate(
  by = "link_headers",
  limit = 5000
)
x$limit

paginate

using options set via cp_init

(alternatively, set options in the call)

x <- can_paginate(
  by = "query_params",
  limit_param = "limit",
  offset_param = "offset",
  limit = 600
)
library(crul)
cli <- crul::HttpClient$new(url = "http://api.gbif.org")
res <- x$paginate(cli$get("v1/occurrence/search"))

Inspect results

res
res$status()
res$content()
res$parse()
res$as_df()

Verbose curl output

x$paginate(cli$get("get"), verbose = TRUE)

http library

Determined by what you pass in to paginate

Meta



ropensci/canpaginate documentation built on May 14, 2022, 12:49 p.m.