Read data and optionally clean column names, keep unique rows, and convert characters to factors
read(
filename,
datadir = NULL,
remove_duplicates = FALSE,
character2factor = FALSE,
clean_colnames = TRUE,
delim_reader = c("data.table", "vroom", "duckdb", "arrow"),
parquet_reader = c("nanoparquet", "arrow"),
xlsx_sheet = 1,
sep = NULL,
quote = "\"",
na_strings = c(""),
output = c("data.table", "tibble", "data.frame"),
attr = NULL,
value = NULL,
verbosity = 1L,
fread_verbosity = 0L,
timed = verbosity > 0L,
...
)data.frame, data.table, or tibble.
Character: filename, full path if datadir = NULL, an
http:// or https:// URL, or an hf://datasets/ path.
Character: Optional path to directory where filename
is located. If not specified, filename must be the full path. Must be
NULL when filename is a URL or an hf:// path.
Logical: If TRUE, keep unique rows only.
Logical: If TRUE, convert character variables to factors.
Logical: If TRUE, clean columns names using clean_colnames.
Character: package to use for reading delimited data.
Character: package to use for reading Parquet files. If undefined and system is WASM, uses "nanoparquet", otherwise "arrow".
Integer or character: Name or number of XLSX sheet to read.
Single character: field separator. If delim_reader = "fread"
and sep = NULL, this is "auto", otherwise ",".
Single character: quote character.
Character vector: Strings to be interpreted as NA values.
For delim_reader = "duckdb", this must be a single string.
Character: "default" or "data.table", If default, return the delim_reader's default data structure, otherwise convert to data.table.
Character: Attribute to set (Optional).
Character: Value to set (if attr is not NULL).
Integer: Verbosity level.
Integer: Verbosity level. Passed to data.table::fread
Logical: If TRUE, time the process and print to console
Additional arguments to pass to data.table::fread,
arrow::read_delim_arrow(), vroom::vroom(),
or readxl::read_excel().
EDG
read is a convenience function to read:
Delimited files using data.table::fread(), arrow::read_delim_arrow(),
vroom::vroom(), or duckdb::duckdb_read_csv()
ARFF files using farff::readARFF()
Parquet files using nanoparquet::read_parquet or arrow::read_parquet()
XLSX files using readxl::read_excel()
DTA files from Stata using haven::read_dta()
FASTA files using seqinr::read.fasta()
RDS files using readRDS()
An http:// or https:// URL is downloaded with utils::download.file()
to a temporary file named after the last segment of the URL path, read like
a local file, and deleted. The file extension in the URL path selects the
reader, as it does for a local file. The download is bounded by
getOption("timeout"), in seconds. A URL with user credentials
(user:password@host) and any scheme other than http, https, and hf
is rejected.
An hf://datasets/<owner>/<name>[@<revision>][/<file>] path reads a file
from a public dataset repository on the Hugging Face Hub, in the path form of
huggingface_hub's HfFileSystem. The revision is a branch, tag, or commit,
main when none is given; a revision containing / is written URL-encoded,
as refs%2Fconvert%2Fparquet. A path that names the repository only reads
the repository's one data file (.parquet, .csv, .tsv, .csv.gz,
.tsv.gz, .rds, .xlsx, .dta, .arff, or .fasta) and is an error when the repository holds more
than one. The revision is resolved to a commit through the Hub API, the file
is downloaded at that commit, and its size and hash are checked against the
Hub's listing. The HF_ENDPOINT environment variable sets the Hub endpoint.
Reading hf:// paths requires the jsonlite package.
if (FALSE) {
# Replace with your own data directory and filename
datadir <- "/Data"
dat <- read("iris.csv", datadir)
# Read from a URL
dat <- read("https://example.org/data/iris.csv")
# Read from a Hugging Face dataset
dat <- read("hf://datasets/rtemis/tcga-pancan-hiseq")
}
Run the code above in your browser using DataLab