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 withvroom::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()
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, ...)
# 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, ...)
Arguments
- path
character()
Path to the file.- ...
Other parameters passed on the functions behind the methods for each file extension.
Examples
# Read CSV file
temp_csv <- tempfile("iris", fileext = ".csv")
write.csv(iris, temp_csv, row.names = FALSE)
read_file(temp_csv)
#> Rows: 150 Columns: 5
#> ── Column specification ────────────────────────────────────────────────────────
#> Delimiter: ","
#> chr (1): Species
#> dbl (4): Sepal.Length, Sepal.Width, Petal.Length, Petal.Width
#>
#> ℹ Use `spec()` to retrieve the full column specification for this data.
#> ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
#> # A tibble: 150 × 5
#> Sepal.Length Sepal.Width Petal.Length Petal.Width Species
#> <dbl> <dbl> <dbl> <dbl> <chr>
#> 1 5.1 3.5 1.4 0.2 setosa
#> 2 4.9 3 1.4 0.2 setosa
#> 3 4.7 3.2 1.3 0.2 setosa
#> 4 4.6 3.1 1.5 0.2 setosa
#> 5 5 3.6 1.4 0.2 setosa
#> 6 5.4 3.9 1.7 0.4 setosa
#> 7 4.6 3.4 1.4 0.3 setosa
#> 8 5 3.4 1.5 0.2 setosa
#> 9 4.4 2.9 1.4 0.2 setosa
#> 10 4.9 3.1 1.5 0.1 setosa
#> # ℹ 140 more rows