R/scrape_m49.R

Defines functions scrape_m49

Documented in scrape_m49

#' scrape_m49
#' This scrapes the m49 geoclassification from the UNSD website. 
#' The URL of the classification is https://unstats.un.org/unsd/methodology/m49/overview/#.
#'
#'
#' @return This function returns a dataframe containing the m49 classification
#' exactly as scraped from the UNSD website.
#'
#' @importFrom httr GET content
#' @importFrom rvest html_nodes html_table
#' @export


scrape_m49 <- function(){
  
  url <- "https://unstats.un.org/unsd/methodology/m49/overview/#"
  website1 <- httr::GET(url)
  
  if(website1$status_code != 200) stop("Website returned error. Check URL for M49 scraping")
  
  
  tbls <- html_nodes(content(website1), "table")
  m49 <-html_table(tbls[[1]],
                   fill=F,
                   header = T)
m49
}
michaelrahija/FAOSDGdata documentation built on June 14, 2020, 5:16 p.m.