R/utils-edm-loop.R

Defines functions edm_loop_query

# Bespoke looping function to manage the weird stuff going on
# with EDM primary sponsors
edm_loop_query <- function(query, jpage, verbose) {
  seq_list <- seq(from = 0, to = jpage, by = 1)

  pages <- list()

  for (i in seq_along(seq_list)) {
    mydata <- jsonlite::fromJSON(paste0(query, seq_list[[i]]), flatten = TRUE)
    if (verbose == TRUE) {
      message("Retrieving page ", seq_list[[i]] + 1, " of ", jpage + 1)
    }
    mydata$result$items$primarySponsorPrinted <-
      as.list(mydata$result$items$primarySponsorPrinted)

    pages[[seq_list[[i]] + 1]] <- mydata$result$items
  }

  df <- tibble::as_tibble(dplyr::bind_rows(pages))

  df
}

Try the hansard package in your browser

Any scripts or data that you put into this service are public.

hansard documentation built on Nov. 13, 2019, 5:06 p.m.