read_file: Read files based on the extension

View source: R/fs_read.R

read_fileR Documentation

Read files based on the extension

Description

read_file() is the backbone of all read_cnt methods, where files are read from their source. The function is a wrapper around read_ext(), that controls the dispatch based on the file extension.

read_ext() controls which packages and functions are used to read the individual file extensions. Below is a list of all the pre-defined methods:

  • default: All extensions not listed below is attempted to be read with vroom::vroom()

  • txt: readr::read_lines()

  • csv: readr::read_csv()

  • parquet: arrow::read_parquet()

  • rds: readr::read_rds()

  • sas7bdat: haven::read_sas()

  • xpt: haven::read_xpt()

  • yml/yaml: yaml::read_yaml()

  • json: jsonlite::read_json()

  • excel: readxl::read_excel()

Usage

read_file(path, ...)

read_ext(path, ...)

## Default S3 method:
read_ext(path, ...)

## S3 method for class 'txt'
read_ext(path, ...)

## S3 method for class 'csv'
read_ext(path, delim = ",", ...)

## S3 method for class 'parquet'
read_ext(path, ...)

## S3 method for class 'rds'
read_ext(path, ...)

## S3 method for class 'sas7bdat'
read_ext(path, ...)

## S3 method for class 'xpt'
read_ext(path, ...)

## S3 method for class 'yml'
read_ext(path, ...)

## S3 method for class 'json'
read_ext(path, ...)

## S3 method for class 'xlsx'
read_ext(path, ...)

Arguments

path

character() Path to the file.

...

Other parameters passed on the functions behind the methods for each file extension.

delim

Single character used to separate fields within a record.

Value

the result of the reading function

Examples

# Read CSV file
temp_csv <- tempfile("iris", fileext = ".csv")
write.csv(iris, temp_csv, row.names = FALSE)
read_file(temp_csv)


connector documentation built on June 8, 2025, 11:36 a.m.