read_repo: Read files directly from a GitHub repository

View source: R/read.R

read_repoR Documentation

Read files directly from a GitHub repository

Description

\Sexpr[results=rd, stage=render]{lifecycle::badge("experimental")}

This utility allows files from a GitHub repository to be read in bulk. The pattern for file names to read (and sub-directories to traverse) can be arbitrarily defined using a regular expression.

Usage

read_repo(
  repo,
  branch = "master",
  pattern = NULL,
  to_tibble = FALSE,
  .f = readr::read_csv,
  n_files = NULL,
  ...
)

Arguments

repo

Name of the GitHub repository containing the files

branch

Name of the branch of the GitHub repository containing the files; default is "master"

pattern

Pattern to match file names to be returned; accepts regex

to_tibble

Boolean indicating whether or not the function should attempt to return a tibble; default is FALSE

.f

Function to read each file whose name complies to pattern argument in the repository; default is read_csv

n_files

Maximum number of files to read in

...

Additional arguments passed to the .f read function

Details

Starting with a call to the GitHub API, this function returns a list of files, which are then filtered to include only those that match the regular expression in the "pattern" argument. The function then internally constructs the raw content URLs and then applies the read function (".f") to each path.

NOTE: The API call is unauthenticated. GitHub API request rate limits apply. For specifics, review the GitHub API documentation.

Value

Contents of the files in the repository that have read using ".f" function supplied. If to_tibble = TRUE then the function will try to stack results on top of each other and return a tibble. If to_tibble = FALSE then the returned object will be a list with as many elements as there are files in the repository that match the "pattern" argument.

Examples

## Not run: 
read_repo(repo = "cdcepi/Flusight-forecast-data",
          branch = "master",
          pattern = "data-forecasts/.*/.*\\.csv",
          to_tibble = TRUE,
          .f = readr::read_csv,
          n_files=10,
          col_types="DcDccdd",
          progress=FALSE)

## End(Not run)

vpnagraj/yawp documentation built on March 31, 2022, 9:56 a.m.