R/xfaostat_helper_funcs.R
FAOSTAT_metadata.Rd
Download and parse the metadata file from the FAOSTAT portal. FAOSTAT_metadata was adapted from the FAOSTAT package.
FAOSTAT_metadata(code = NULL)
FAOSTAT dataset code if filtering specific dataset; NULL by default and return all dataset info
Dataframe including the metadata of FAOSTAT including URL for download, updating date, detailed descriptions, etc.
FAOSTAT_metadata
#> function (code = NULL){
#> FAOxml <- XML::xmlParse(xml2::read_xml("http://fenixservices.fao.org/faostat/static/bulkdownloads/datasets_E.xml"))
#> metadata <- XML::xmlToDataFrame(FAOxml, stringsAsFactors = FALSE)
#> names(metadata) <- tolower(gsub("\\.", "_", names(metadata)))
#>
#> # Bug fix for CB; can remove later if FAOSTAT update the link later
#> metadata["CB" == metadata[, "datasetcode"],"filelocation"] <-
#> "https://fenixservices.fao.org/faostat/static/bulkdownloads/CommodityBalances_(non-food)_E_All_Data_(Normalized).zip"
#>
#> if (!is.null(code)) {
#> metadata <- metadata[code == metadata[, "datasetcode"],]
#> }
#>
#> return(metadata)
#> }
#> <bytecode: 0x0000000042a70840>
#> <environment: namespace:gcamfaostat>