timriffe / DDSQLtools

DemoData SQL tools. Wrappers for the DemoTools package to work with UNPD SQL data format
https://timriffe.github.io/DDSQLtools
Other
5 stars 1 forks source link

getrecorddata error behavior #53

Open timriffe opened 2 years ago

timriffe commented 2 years ago

A feature, not to be implemented before summer 2022: if a record is requested and not available you get a 404 error. Let's trap that error and return it as a message, and make the function return NULL. Can't do this change now because it's used in production at the moment @cimentadaj

liuyanguu commented 2 years ago

This is a very helpful note. For example, to get all process types for a country we could do:

#' get all data process types for location x 
get.by.location <- function(x){
  get.all.types <- function(type0){
    res0 <- tryCatch(
      {
        get_recorddata(
          dataProcessTypeIds = type0,
          startYear = 1920,
          endYear = 2030,
          indicatorIds  = c(239, 229, 234, 221),
          locIds = x,             
          locAreaTypeIds = 2,      ## "Whole area"
          subGroupIds = 2,         ## "Total or All groups"
          includeUncertainty = TRUE)
      }, error = function(cond) return(NULL)
    )
    return(res0)
  }
  return(rbindlist(lapply(0:15, get.all.types)))
}