download-case-projects: Download New Interview Tool Data

Description Usage Arguments Value Examples

Description

download_nit() downloads records from the New Interview Tool (NIT) project

download_nca() downloads records from the New Case Assignment (NCA) project

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
download_nit(
  api_token = Sys.getenv("redcap_NIT_token"),
  headers = c("raw", "label"),
  values = c("label", "raw"),
  filter = NULL,
  fields = c("record_id", "date", "numb_contacts_16", "start", "specimendate",
    "case_interview_complete"),
  dir = "V:/EPI DATA ANALYTICS TEAM/COVID SANDBOX REDCAP DATA/Data for R/nit/",
  file = paste0("nit_data_", str_date(), ".csv"),
  force = FALSE
)

download_nca(
  api_token = Sys.getenv("redcap_NCA_token"),
  headers = c("raw", "label"),
  values = c("label", "raw"),
  filter = NULL,
  fields = NULL,
  dir = "V:/EPI DATA ANALYTICS TEAM/COVID SANDBOX REDCAP DATA/Data for R/nca/",
  file = paste0("nca_data_", str_date(), ".csv"),
  force = FALSE
)

Arguments

api_token

character. API token/key for accessing the project programmatically. Best practice is to set as an environment variable and retrieve using Sys.getenv("token_environment_variable"). See env-variables for more information.

headers

"raw" or "label". Should column names ("headers") be exported as the raw variable names ("raw", the default) or the label shown in the UI ("label")?

values

"raw" or "label". Should values in multiple-choice and checkbox fields be exported as the raw coded value ("raw", the default) or the label for the coded value ("label")?

filter

character. REDcap filtering logic to apply prior to download. This must be in the REDcap logic syntax.

fields

character. A vector of field names to include; if NULL, all fields will be downloaded.

dir

character. Directory to save data; this should usually remain unchanged.

file

character. File name for data; this should usually remain unchanged. The resulting file will always have a "csv" extension; if you pass a file name without a "csv" extension, the function will replace it with a warning.

force

Should the download overwrite an existing file, if one exists? The default is FALSE, which errors if an existing file is found.

Value

The path to the data as an fs_path character vector

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
## Not run: 
  # Download the current NIT data
  download_nit()

  # Download NIT and load immediately
  nit_data <- load_nit(download_nit())

  # Do the same with pipe (`%>%`)
  nit_data <- download_nit() %>% load_nit()

  # Overwrite the previous file
  download_nit(force = TRUE)

  # Download NCA data
  download_nca()

  # Download NCA and overwrite previous file
  nca_data <- download_nca() %>% load_nca()

## End(Not run)

jesse-smith/covidprod documentation built on Oct. 11, 2021, 5:34 p.m.