Skip to contents

tar_redcap() builds a set of dynamic targets to pull REDCap metadata and form-level data using the redcapAPI backend. It supports dynamic branching across all instruments and offers flexible control over when data is re-fetched via cue behavior (e.g., logging-based updates, always re-fetching, or never rerunning unless missing).

Usage

tar_redcap(
  name,
  con,
  mode = c("logging", "always", "thorough", "never"),
  fetch_records = redcap_fetch_records,
  instruments = NULL,
  ...
)

Arguments

name

Symbol. A name stem for the REDCap targets (e.g., redcap will generate redcap_meta_db and one target per instrument prefixed with redcap_).

con

A redcapAPI::redcapConnection object.

mode

Character string indicating how target invalidation should occur:

  • "logging": re-run only when REDCap logs show changes (requires user access to logs).

  • "always": always re-run REDCap pulls regardless of changes.

  • "thorough": default targets invalidation (based on dependencies and metadata).

  • "never": never re-run unless missing or errored previously.

fetch_records

A function used to fetch records for each REDCap form. Must accept arguments con and forms, along with additional optional arguments via .... Defaults to redcap_fetch_records().

instruments

Optional character vector of instrument (form) names to fetch from REDCap. If NULL (default), all available instruments will be fetched using fetch_redcap_instruments(). If supplied, the values must be valid instrument names present in the REDCap project. This allows selective fetching of only a subset of forms.

...

Additional arguments passed to fetch_records, such as batch_size, drop_fields, or label formatting options.

Value

A list of tar_target() and tar_map() objects, including:

  • <name>_meta_db: a target for REDCap metadata.

  • One dynamic target per REDCap instrument, each named <name>_<instrument>.

Examples

if (FALSE) { # \dontrun{
tar_redcap(
  name = redcap,
  con = redcap_con,
  mode = "logging",
  batch_size = 1000
)

# Custom record fetcher example:
custom_fetch <- function(con, forms, ...) {
  redcapAPI::exportRecords(con, forms = forms, labels = TRUE, ...)
}

tar_redcap(
  name = redcap,
  con = redcap_con,
  mode = "always",
  fetch_records = custom_fetch
)
} # }