get_data: Generic Get Data Function

Description Usage Arguments Value See Also Examples

View source: R/get_data.R

Description

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.

Usage

1
2
3
4
get_data(url = NULL, data_trans_fn = NULL, download_data = TRUE,
  save = TRUE, save_name = NULL, return = TRUE, verbose = TRUE,
  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 TRUE. 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

1
2
3
4
tb_burden <- get_data(url = "https://extranet.who.int/tme/generateCSV.asp?ds=estimates",
save_name = "TB_burden")

head(tb_burden)

getTBinR documentation built on Nov. 16, 2018, 1:17 a.m.