read_csv_duckdb: Read CSV files using DuckDB

View source: R/read_csv_duckdb.R

read_csv_duckdbR Documentation

Read CSV files using DuckDB

Description

read_csv_duckdb() reads a CSV file using DuckDB's read_csv_auto() table function.

Usage

read_csv_duckdb(
  path,
  ...,
  prudence = c("thrifty", "lavish", "stingy"),
  options = list()
)

Arguments

path

Path to files, glob patterns * and ⁠?⁠ are supported.

...

These dots are for future extensions and must be empty.

prudence

Memory protection, controls if DuckDB may convert intermediate results in DuckDB-managed memory to data frames in R memory.

  • "thrifty": up to a maximum size of 1 million cells,

  • "lavish": regardless of size,

  • "stingy": never.

The default is "thrifty" for the ingestion functions, and may be different for other functions. See vignette("prudence") for more information.

options

Arguments to the DuckDB read_csv_auto table function.

See Also

read_parquet_duckdb(), read_json_duckdb()

Examples

# Create simple CSV file
path <- tempfile("duckplyr_test_", fileext = ".csv")
write.csv(data.frame(a = 1:3, b = letters[4:6]), path, row.names = FALSE)

# Reading is immediate
df <- read_csv_duckdb(path)

# Names are always available
names(df)

# Materialization upon access is turned off by default
try(print(df$a))

# Materialize explicitly
collect(df)$a

# Automatic materialization with prudence = "lavish"
df <- read_csv_duckdb(path, prudence = "lavish")
df$a

# Specify column types
read_csv_duckdb(
  path,
  options = list(delim = ",", types = list(c("DOUBLE", "VARCHAR")))
)

duckdblabs/duckplyr documentation built on March 5, 2025, 3:46 a.m.