Skip to content

Data Operations.R

rachitest edited this page May 12, 2025 · 1 revision

The data_operations.R script automates data fetching, storage, and handling operations using REDCap and DuckDB databases.

Dependencies

  • duckdb
  • fs
  • REDCapR

Functions

  • get_data(token):

    • Fetches data directly from REDCap API using provided API token. The default token is set as an environment variable (REDCAP_API_TOKEN).
  • save_data(directory):

    • Checks and creates the specified directory if it does not exist.
    • Connects to DuckDB database.
    • Writes the fetched REDCap data into a DuckDB database (APS-BL table).
    • Ensures database connection is safely closed after data storage.

Workflow

  1. Data fetched from REDCap API.
  2. Data stored in DuckDB format in directory assets/data/.
  3. Messages confirm successful data writing operations.

Usage

Run this script regularly (every week) or as needed to update local datasets from REDCap.

Clone this wiki locally