Learn R Programming

StatsTFLValR (version 1.0.0)

get_data: Load Data Files of Various Formats

Description

Loads one or more data files from a given directory. Supports multiple file types commonly used in clinical trials: .sas7bdat, .xpt, .csv, .xls, and .xlsx.

Usage

get_data(dir, file_names = NULL)

Value

If exactly one file is loaded, returns the dataset. If multiple files are loaded, returns a named list of datasets.

Arguments

dir

Character. Path to the directory containing data files.

file_names

Character vector. Optional base names (with or without extensions) to load; if NULL, loads all supported files from the directory.

Details

Automatically detects file extensions and returns each dataset using its base file name (e.g., "adsl.xpt" becomes adsl).

If multiple files with the same base name but different extensions exist (e.g., adsl.csv and adsl.sas7bdat), the function stops and reports the duplicates to avoid ambiguity.

Examples

Run this code
if (FALSE) {

adsl <- get_data("path/to/adam", "adsl")

ds <- get_data("path/to/adam")

adsl <- ds$adsl

}

Run the code above in your browser using DataLab