If the data is found locally in the temporary directory then this function will load the data into R. Otherwise if download_data = TRUE then the data will be retrieved from the specified URL. Data can then be saved to the temporary directory by specifying save = TRUE.

get_data(
  url = NULL,
  data_trans_fn = NULL,
  download_data = TRUE,
  save = TRUE,
  save_name = NULL,
  return = TRUE,
  verbose = FALSE,
  use_utils = FALSE,
  use_direct_download = FALSE,
  retry_download = TRUE
)

Arguments

url

Character string, indicating the url of the data to download.

data_trans_fn

Function that takes a data.table as input and returns a single dataframe of any type. If not specified defaults to transforming the data into a tibble.

download_data

Logical, defaults to TRUE. If not found locally should the data be downloaded from the specified URL?

save

Logical, should the data be saved for reuse during the current R session. Defaults to TRUE. If TRUE then the data is saved to the temporary directory specified by tempdir.

save_name

Character string, name to save the data under. Defaults to NULL.

return

Logical, should the data be returned as a dataframe. Defaults to TRUE.

verbose

Logical, defaults to FALSE. Should additional status and progress messages be displayed.

use_utils

Logical, defaults to FALSE. Used for testing alternative data download function. When TRUE data is downloaded using read.csv.

use_direct_download

Logical, defaults to FALSE. Used for testing alternative data download function. When TRUE data is downloaded using download.file.

retry_download

Logical defaults to TRUE. When TRUE, if downloading fails, the function will try repeatedly to download the data within 3 seconds, up to 3 times.

Value

The data loaded from a local copy or downloaded from the given url as a dataframe, exact format specified by data_trans_fn

See also

get_tb_burden get_data_dict

Examples

tb_burden <- get_data( url = "https://extranet.who.int/tme/generateCSV.asp?ds=estimates", save_name = "TB_burden" ) head(tb_burden)
#> # A tibble: 6 x 50 #> country iso2 iso3 iso_numeric g_whoregion year e_pop_num e_inc_100k #> <chr> <chr> <chr> <int> <chr> <int> <int> <dbl> #> 1 Afghan… AF AFG 4 EMR 2000 20779953 190 #> 2 Afghan… AF AFG 4 EMR 2001 21606988 189 #> 3 Afghan… AF AFG 4 EMR 2002 22600770 189 #> 4 Afghan… AF AFG 4 EMR 2003 23680871 189 #> 5 Afghan… AF AFG 4 EMR 2004 24726684 189 #> 6 Afghan… AF AFG 4 EMR 2005 25654277 189 #> # … with 42 more variables: e_inc_100k_lo <dbl>, e_inc_100k_hi <dbl>, #> # e_inc_num <int>, e_inc_num_lo <int>, e_inc_num_hi <int>, #> # e_tbhiv_prct <dbl>, e_tbhiv_prct_lo <dbl>, e_tbhiv_prct_hi <dbl>, #> # e_inc_tbhiv_100k <dbl>, e_inc_tbhiv_100k_lo <dbl>, #> # e_inc_tbhiv_100k_hi <dbl>, e_inc_tbhiv_num <int>, e_inc_tbhiv_num_lo <int>, #> # e_inc_tbhiv_num_hi <int>, e_mort_exc_tbhiv_100k <dbl>, #> # e_mort_exc_tbhiv_100k_lo <dbl>, e_mort_exc_tbhiv_100k_hi <dbl>, #> # e_mort_exc_tbhiv_num <int>, e_mort_exc_tbhiv_num_lo <int>, #> # e_mort_exc_tbhiv_num_hi <int>, e_mort_tbhiv_100k <dbl>, #> # e_mort_tbhiv_100k_lo <dbl>, e_mort_tbhiv_100k_hi <dbl>, #> # e_mort_tbhiv_num <int>, e_mort_tbhiv_num_lo <int>, #> # e_mort_tbhiv_num_hi <int>, e_mort_100k <dbl>, e_mort_100k_lo <dbl>, #> # e_mort_100k_hi <dbl>, e_mort_num <int>, e_mort_num_lo <int>, #> # e_mort_num_hi <int>, cfr <dbl>, cfr_lo <dbl>, cfr_hi <dbl>, cfr_pct <int>, #> # cfr_pct_lo <int>, cfr_pct_hi <int>, c_newinc_100k <dbl>, c_cdr <dbl>, #> # c_cdr_lo <dbl>, c_cdr_hi <dbl>