read_github_csv_dir

read_github_csv_dir(
    path,
    ref='main',
    repo=None,
    token=None,
    pattern='\\.csv$',
    **kwargs,
)

Read all CSV files from a GitHub directory.

Uses the GitHub Contents API to list directory contents, filter for CSV files, and read each into a pandas DataFrame.

Parameters

Name Type Description Default
path str Path to directory in repository (e.g., “data” or “inst/extdata”) or full GitHub URL. Use “” for repository root. required
ref str Git reference (branch, tag, or commit SHA) "main"
repo str Repository in “owner/name” format (required if path is not a full URL) None
token str GitHub personal access token (PAT). If None, uses _github_token() None
pattern str Regex pattern to filter files (case-insensitive) r"\.csv$"
**kwargs Additional arguments passed to pd.read_csv() {}

Returns

Name Type Description
Dict[str, pd.DataFrame] Dictionary mapping filenames (without .csv extension) to DataFrames

Raises

Name Type Description
ValueError If no GitHub token found or path is invalid
PermissionError If authentication fails or SSO authorization required
FileNotFoundError If directory not found

Examples

>>> # Read all CSVs from a directory
>>> data = read_github_csv_dir(
...     "inst/extdata",
...     repo="salmon-data-mobilization/metasalmon",
...     ref="main"
... )
>>> print(data.keys())  # dict_keys(['column_dictionary', 'nuseds-fraser-coho-sample', ...])
>>> print(data['column_dictionary'].head())
Back to top