Current datum releases expose the exact configuration
schema in the binary, together with the required and optional fields for
every source handler included in the build. datur uses that
live metadata to make .data.yaml edits safer: an edit is
validated before the original file is replaced, and a failed validation
leaves it untouched.
The executable is still the source of truth. These helpers verify that the installed release supports configuration metadata, even though checking existing projects also works with older supported releases.
Initialize a project (datum 1.6.0+)
datum_init() exposes datum’s non-interactive
initialization modes. It refuses to overwrite an existing
configuration:
datum_init(empty = TRUE, wd = project)
datum_init(
id = "exchange_rates",
type = "file",
source = "upstream/rates.csv",
target = "data/rates.csv",
policy = "update",
ignore = TRUE,
wd = project
)Inspect the installed configuration contract
datum_schema() parses the JSON Schema returned by
datum schema:
schema <- datum_schema()
schema$title
#> [1] "Datum Configuration"
schema$properties$datasets$items$properties$policy$enum
#> [[1]]
#> [1] "fail"
#>
#> [[2]]
#> [1] "update"
#>
#> [[3]]
#> [1] "log"datum_types() reports the source handlers available in
this particular build. That distinction matters because optional build
tags can change the available handlers.
names(datum_types())
#> [1] "command" "file" "git" "http"
datum_types(c("http", "file"))
#> $http
#> $http$type
#> [1] "http"
#>
#> $http$description
#> [1] "HTTP/HTTPS URL source"
#>
#> $http$fields
#> $http$fields[[1]]
#> $http$fields[[1]]$name
#> [1] "type"
#>
#> $http$fields[[1]]$required
#> [1] TRUE
#>
#> $http$fields[[1]]$description
#> [1] "Must be \"http\"."
#>
#>
#> $http$fields[[2]]
#> $http$fields[[2]]$name
#> [1] "url"
#>
#> $http$fields[[2]]$required
#> [1] TRUE
#>
#> $http$fields[[2]]$description
#> [1] "HTTP or HTTPS URL to fetch data from"
#>
#>
#> $http$fields[[3]]
#> $http$fields[[3]]$name
#> [1] "headers"
#>
#> $http$fields[[3]]$required
#> [1] FALSE
#>
#> $http$fields[[3]]$description
#> [1] "Optional HTTP request headers"
#>
#>
#> $http$fields[[4]]
#> $http$fields[[4]]$name
#> [1] "body"
#>
#> $http$fields[[4]]$required
#> [1] FALSE
#>
#> $http$fields[[4]]$description
#> [1] "Optional HTTP request body; a non-empty body uses POST instead of HEAD/GET"
#>
#>
#>
#>
#> $file
#> $file$type
#> [1] "file"
#>
#> $file$description
#> [1] "Local or network file (or directory) source"
#>
#> $file$fields
#> $file$fields[[1]]
#> $file$fields[[1]]$name
#> [1] "type"
#>
#> $file$fields[[1]]$required
#> [1] TRUE
#>
#> $file$fields[[1]]$description
#> [1] "Must be \"file\"."
#>
#>
#> $file$fields[[2]]
#> $file$fields[[2]]$name
#> [1] "path"
#>
#> $file$fields[[2]]$required
#> [1] TRUE
#>
#> $file$fields[[2]]$description
#> [1] "Absolute or relative path to the source file or directory. If this is a directory (auto-detected at run time), the entire tree is recreated under 'target', and files deleted upstream are removed from 'target' on the next fetch."Keep secrets outside .data.yaml (datum 1.5.0+)
Starting with datum 1.5.0, any YAML string value can
contain a ${NAME} environment reference. datum
expands it after parsing the YAML and before validating or using the
configuration. The placeholder can therefore be written with
datur just like any other source or target value:
private_api <- datum_source(
"http",
url = "https://api.example.com/export?token=${API_TOKEN}"
)
datum_dataset_add(
id = "private_export",
desc = "Authenticated API export",
target = "${DATA_DIR}/private.csv",
source = private_api,
policy = "update"
)Supply the variables through the environment inherited by
datum. For example, they may be injected by a CI secret
store or set in the R process before the call:
Sys.setenv(
API_TOKEN = "value-supplied-at-runtime",
DATA_DIR = "data"
)
datum_check(quiet = TRUE)The expansion rules are deliberately strict:
- variable names must match
[A-Za-z_][A-Za-z0-9_]*; - an unset variable is a configuration error, while a variable explicitly set to an empty string is allowed;
- only
${NAME}is expanded, so plain$NAMEremains available to command sources; -
$${NAME}produces the literal text${NAME}; and - substitution applies to YAML values, not mapping keys.
Quote a placeholder that replaces a whole value when the expanded
value must remain a string. Placeholders remain in
.data.yaml, and expanded values are not written to
.data.lock.yaml. This prevents committing the resolved
secret, but it is not an output-redaction boundary: downstream URLs,
commands, and errors may still expose it. Prefer purpose-built
authentication variables such as the Git handler’s
GIT_TOKEN when available, and do not print secrets from
command sources.
datur’s configuration helpers validate the
placeholder-bearing document before writing it. Retain any literal
prefix required by the schema—for example, keep https://
outside the placeholder in an HTTP URL. datum then
validates the expanded value again at runtime.
Construct a source
datum_source() checks field names and required values
against datum_types(). It returns an ordinary named list,
so you can inspect, store, or modify it before adding a dataset.
primary <- datum_source(
"file",
path = "upstream/rates.csv"
)
fallback <- datum_source(
"file",
path = "offline-cache/rates.csv"
)Datum 1.6.0 HTTP sources may provide a named header mapping and an optional request body. A non-empty body makes datum use POST:
private_api <- datum_source(
"http",
url = "https://api.example.com/export",
headers = list(Authorization = "Bearer ${API_TOKEN}"),
body = '{"format":"csv"}'
)Unknown fields, missing required fields, unavailable source types,
and empty values fail before .data.yaml is touched.
Add datasets
Use source for one source or sources for
ordered fallback. If the config does not exist,
datum_dataset_add() starts a version 1 document. Paths are
interpreted by datum relative to the project working directory, so pass
the same wd you use for checks when working outside the
current R directory.
datum_dataset_add(
id = "exchange_rates",
desc = "Daily exchange rates",
target = "data/rates.csv",
sources = list(primary, fallback),
policy = "update",
ignore = TRUE,
wd = project
)
datum_dataset_add(
id = "retained_data",
desc = "A second local dataset",
target = "data/retained.csv",
source = datum_source("file", path = "upstream/retained.csv"),
policy = "update",
wd = project
)The full resulting document—not only the new dataset—is checked against the installed schema and the available source types. Existing defaults and other datasets are retained.
Update datasets
Only arguments you supply are changed. Supplying source
replaces an existing sources list, and supplying
sources replaces source. Use
policy = NULL or ignore = NULL to remove a
dataset-level override and fall back to the config default.
datum_dataset_update(
"exchange_rates",
desc = "Rates with an offline fallback",
policy = NULL,
wd = project
)
datum_dataset_update(
"exchange_rates",
source = primary,
wd = project
)Dataset identifiers are immutable in this API. Remove and re-add a definition when an identifier itself must change, then decide how its old lock entry should be handled.
Audit and remove datasets
datum_audit() combines config and lockfile state without
contacting any data source. Its records distinguish configured and
pinned datasets from pending, deleted, and orphaned entries.
audit <- datum_audit(wd = project)
as.data.frame(audit)
#> id status in_config policy target remote_fingerprint
#> 1 exchange_rates pending TRUE fail data/rates.csv <NA>
#> 2 retained_data pending TRUE update data/retained.csv <NA>
#> local_sha256 checked_at deleted_at inaccessible_at inaccessible_error
#> 1 <NA> <NA> <NA> <NA> <NA>
#> 2 <NA> <NA> <NA> <NA> <NA>
#> note
#> 1 never fetched
#> 2 never fetched
subset(as.data.frame(audit), status != "ok")
#> id status in_config policy target remote_fingerprint
#> 1 exchange_rates pending TRUE fail data/rates.csv <NA>
#> 2 retained_data pending TRUE update data/retained.csv <NA>
#> local_sha256 checked_at deleted_at inaccessible_at inaccessible_error
#> 1 <NA> <NA> <NA> <NA> <NA>
#> 2 <NA> <NA> <NA> <NA> <NA>
#> note
#> 1 never fetched
#> 2 never fetcheddatum_dataset_remove() removes a definition from
.data.yaml. In an interactive R session it asks whether the
tracked local files should also be deleted. In a script, state the
choice explicitly:
# Keep the downloaded file.
datum_dataset_remove("exchange_rates", delete = FALSE, wd = project)Pass delete = TRUE instead to run
datum delete before removing the YAML definition.
Deletion happens first because datum needs the still-present
definition to locate the target. It marks the lock entry deleted; after
removing the config definition, datum_audit() can still
show that historical entry. Use datum’s low-level unlock
command through datum_run() if you deliberately want to
forget it completely.
To delete local files while keeping the dataset definition, call
datum_delete() directly. It asks for confirmation in an
interactive session; automation must opt in with
yes = TRUE.
datum_delete("cached_data", yes = TRUE, wd = project)Datum then skips deleted datasets until its undelete
command is run. The .data.yaml file itself is never changed
by datum_delete().
