Download data.un.org tables as csvs

download_undata_table(
  table_url,
  output_dir,
  record_limit = 1e+05,
  download_sleep = 30,
  base_url = "http://data.un.org/Data.aspx",
  downloader_url = "http://data.un.org/Handlers/DownloadHandler.ashx"
)

Arguments

table_url

[character(1)]
The full url to a specific table. If filters, columns, sort order or other options are selected, use the 'Link to this page' -> 'Update' button to update the table_url.

output_dir

[character(1)]
Directory to save separate downloaded data files.

record_limit

[numeric(1)]
Upper limit of records/rows that you can download at once.

download_sleep

[numeric(1)]
Seconds to sleep/wait between download calls.

base_url

[character(1)]
The base url of the data.un.org site. Default is 'http://data.un.org/Data.aspx'.

downloader_url

The base url of the data.un.org site download interfact. Default is 'http://data.un.org/Handlers/DownloadHandler.ashx'.

Value

[character()] file paths for each separate file downloaded.

Details

A list of all possible tables is shown here http://data.un.org/Explorer.aspx. Currently this function assumes one is able to filter by Year when downloading data.

The 'data.un.org' website does not allow one to download more than 100,000 records at a time. In order to account for this, we loop through groups of years that stay below the limit. This means table_url should not already include specified filters for years as this function is intended to download all years of data.

See also

Examples

if (FALSE) { table <- download_undata_table( table_url = "http://data.un.org/Data.aspx?d=POP&f=tableCode:7;areaCode:0&v=1", output_dir = tempdir() ) }