R/utils.R

Defines functions .as_row .as_df

BASE_URL <- "https://chroniclingamerica.loc.gov"

.as_row <- function(row){
  r <- purrr::map(row, function(x){
    if(is.null(x)) 
      return(NA)
    
    if(length(x) > 1)
      x <- list(x)

    return(x)
  })

  tibble::as_tibble(r)
}

.as_df <- function(articles){
  articles <- purrr::flatten(articles)
  purrr::map_df(articles, .as_row)
}
news-r/loc documentation built on Feb. 29, 2020, 3:05 a.m.