DRDataRaft/ docs
GitHub ↗

dr_write_data()

Starts the normal landing, validation and publication workflow. Without a contract, the first successful write establishes a structural schema. Later writes must match that schema. Automatic numeric columns accept integers and decimals; explicit integer contracts remain strict. Missing values are allowed; empty tables are blocked. No keys, business rules, owners or freshness deadlines are guessed.

Usage

dr_write_data(
  lake,
  data,
  name = NULL,
  contract = NULL,
  reader = NULL,
  code_version = NULL,
  input_contract = NULL,
  cache = NULL,
  partition_by = character(),
  ...
)

Arguments

lake
Connected lake or dr_lake_config().


data
Data frame, path to a local file, or a zero-argument function returning a data frame. A source function is called once per write before cache lookup; its returned data is archived as RDS. Use it to connect existing API or database clients. It requires name and does not archive the original transport response.


name
Optional asset name. Defaults to the data frame's variable name or the file name without its extension. Expressions need an explicit name. Names start with a letter and use letters, digits, underscores or dots.


contract
Optional publication contract. Omit for structural checks.


reader
Optional file reader taking a path and returning a data frame.


code_version
Optional code and dependency version for cache reuse.


input_contract
Optional separate gate before writing Raw.


cache
Optional reuse policy. Defaults to safe reuse for built-in readers and structural checks; custom callbacks need code_version to enable reuse. FALSE always runs validation again.


partition_by
Optional column names identifying complete partitions to replace. Omit to replace the whole asset. Every row of each supplied partition replaces that partition; other partitions remain published.


...
Publication options, such as business_date, notify, layer and stop_on_failure.

Value

A dr_run_result with status, release ID and quality results. Successful results retain their exact release and connection configuration for dataraft.core::dr_collect(), dataraft.core::dr_product(), dataraft.core::dr_step_lookup() and dataraft.metrics::dr_measure(), including after the original connection closes. Caller-owned connections remain open. dataraft.core::dr_quality() explains a failure.

Details

Supply contract whenever you need business checks or an intentional schema change. Once an execution attempt uses an explicit contract, subsequent writes must supply one too, even if that attempt was blocked. This prevents accidentally dropping its rules. Draft contracts still require dataraft.core::dr_contract_confirm().

Data frames are archived as RDS snapshots. File inputs preserve their original bytes before parsing. CSV, TSV and RDS have native readers; Excel uses optional readxl. CSV/TSV use base R type inference; use reader for specific parsing requirements. The first file may be parsed twice to establish and validate its schema. Readers must be deterministic and must not modify their input.

Definition versions are derived automatically. Use dataraft.core::dr_product() and dataraft.core::dr_run() when composing transformations or controlling definition versions. Built-in readers and structural checks can reuse the current release. Custom readers or rules run again by default because captured values and external state cannot be fingerprinted reliably. Supply code_version to enable reuse and update it whenever code, dependencies or captured values change.

Examples

\dontshow{if (requireNamespace("duckdb", quietly = TRUE)) withAutoprint(\{ # examplesIf}
root <- tempfile("dataraft-")
lake <- dr_open_lake(root)
orders <- data.frame(id = 1:3, amount = c(25, 75, 50))
dr_write_data(lake, orders)
dr_read_release(lake, "orders")
contract <- dataraft.core::dr_contract("orders.checked",
  columns = c(id = "integer", amount = "numeric"), key = "id")
dr_write_data(lake, orders, contract = contract)
dr_close_lake(lake)
unlink(root, recursive = TRUE)
\dontshow{\}) # examplesIf}

See also

dr_open_lake(), dr_read_release(), dataraft.core::dr_product(), dataraft.core::dr_run()
Documentation source snapshot · View source at 113c179 ↗
Code examples are documented source examples; they are not executed in this website build.

Search documentation

Search functions, packages and guides.