Lazy-read a CSV file, optionally: filter rows, remove duplicates, clean column names, convert character to factor, collect.
ddb_data(
filename,
datadir = NULL,
sep = ",",
header = TRUE,
quotechar = "",
ignore_errors = TRUE,
make_unique = TRUE,
select_columns = NULL,
filter_column = NULL,
filter_vals = NULL,
character2factor = FALSE,
collect = TRUE,
progress = TRUE,
returnobj = c("data.table", "data.frame"),
data.table.key = NULL,
clean_colnames = TRUE,
verbosity = 1L
)data.frame or data.table if collect is TRUE, otherwise a character with the SQL query
Character: file name; either full path or just the file name,
if datadir is also provided.
Character: Optional path if filename is not full path.
Character: Field delimiter/separator.
Logical: If TRUE, first line will be read as column names.
Character: Quote character.
Logical: If TRUE, ignore parsing errors.
Logical: If TRUE, keep only unique rows.
Character vector: Column names to select.
Character: Name of column to filter on, e.g. "ID".
Numeric or Character vector: Values in filter_column to keep.
Logical: If TRUE, convert character columns to factors.
Logical: If TRUE, collect data and return structure class
as defined by returnobj.
Logical: If TRUE, enable the DuckDB progress bar.
Character: "data.frame" or "data.table" object class to
return. If "data.table", data.frame object returned from
DBI::dbGetQuery is passed to data.table::setDT.
Character: If set, this corresponds to a column name in the dataset. This column will be set as key in the data.table output.
Logical: If TRUE, clean colnames with clean_colnames.
Integer: Verbosity level.
EDG
if (FALSE) {
# Requires local CSV file; replace with your own path
ir <- ddb_data("/Data/massive_dataset.csv",
filter_column = "ID",
filter_vals = 8001:9999
)
}
Run the code above in your browser using DataLab