Extracts values from the XML Data Structure Definition (DSD) file

extract_dsd(concept = NULL, dsd_xml = NULL, lang = "en")

Arguments

concept

a character vector with a concept id

dsd_xml

an XML file with DSD content

lang

a character string either en, de or fr to define the language version for the name column of the DSD. It is used only in the new API. The default is en - English.

Value

a matrix with 3 columns if the provided concept has a code list in the DSD file. The first column is the provided concept. The second column is the possible codes under the given concept. The last column is the name/description for the code in the second column, which can be used as labels.

Details

It is a sub-function to use in the get_eurostat_dsd function.

Examples

# \donttest{
id<-"med_rd6"
cfg<-get("cfg",envir=restatapi::.restatapi_env)
rav<-get("rav",envir=restatapi::.restatapi_env)
dsd_url <- paste0(eval(
     parse(text=paste0("cfg$QUERY_BASE_URL$'",rav,"'$ESTAT$metadata$'2.1'$datastructure"))
   ),"/",eval(
     parse(text=paste0("cfg$QUERY_PRIOR_ID$'",rav,"'$ESTAT$metadata"))
   ),id,"?",eval(
     parse(text=paste0("cfg$QUERY_PARAMETERS$'",rav,"'$metadata[2]"))
   ),"=",eval(
     parse(text=paste0("cfg$DATAFLOW_REFERENCES$'",rav,"'$datastructure[1]"))
   )
 )
if (!(grepl("amzn|-aws|-azure ",Sys.info()['release']))) options(timeout=2)
tryCatch({
  dsd_xml<-xml2::read_xml(dsd_url)}, 
  error=function(e){
  message("Unable to download the xml file.\n",e)}, 
  warning=function(w){
  message("Unable to download the xml file.\n",w)}) 
if (exists("dsd_xml")) extract_dsd("FREQ",dsd_xml) 
#>       concept xml_clc xml_cln                  
#>  [1,] "FREQ"  "P"     "Pluri-annual"           
#>  [2,] "FREQ"  "A"     "Annual"                 
#>  [3,] "FREQ"  "S"     "Half-yearly, semesterly"
#>  [4,] "FREQ"  "Q"     "Quarterly"              
#>  [5,] "FREQ"  "M"     "Monthly"                
#>  [6,] "FREQ"  "W"     "Weekly"                 
#>  [7,] "FREQ"  "B"     "Daily - business week"  
#>  [8,] "FREQ"  "D"     "Daily"                  
#>  [9,] "FREQ"  "H"     "Hourly"                 
#> [10,] "FREQ"  "I"     "Irregular / A-periodic" 
#> [11,] "FREQ"  "NAP"   "Not applicable"         
options(timeout=60)
# }