Skip to contents

datur is deliberately a thin integration layer. datum owns source access, fingerprinting, policies, and lockfile updates; datur owns safe process execution, protocol validation, typed conditions, and convenient R objects.

The pkgdown version of this vignette is built against the latest published datum release. Its output is produced during the site build from disposable local files; no output transcript is stored in the vignette source.

1. Install or discover the executable

Installing datum through datur is always explicit. The default resolves the latest GitHub release and chooses the archive matching the current operating system and CPU architecture:

download <- datum_download()
if (download$downloaded) {
  options(datur.datum_path = download$path)
}

For a reproducible toolchain, reuse the resolved release and pin the destination:

datum_download(
  version = download$version,
  destination = "~/bin/datum",
  overwrite = TRUE
)

The release archive is checked against checksums.txt before its executable is installed. If GitHub exceeds the requested timeout, no partial binary is installed; the returned object’s url and asset fields identify the manual download instead.

Alternatively, install datum separately and let datur discover it:

datum_available()
#> [1] TRUE
datum_path()
#> [1] "/home/runner/work/_temp/datum"
datum_version()
#> [1] '1.6.0'

Discovery precedence is explicit and deterministic:

  1. executable = on the function call;
  2. options(datur.datum_path = ...);
  3. DATUM_PATH;
  4. a valid path cached by an earlier explicit or automatic lookup;
  5. Sys.which("datum").

Explicit paths, automatic PATH discovery, and successful version parsing are cached. Use datum_path(refresh = TRUE) or datum_version(refresh = TRUE) after replacing the executable in a long-running R session.

2. Configure a datum project

This site build created a disposable project with a local-file source, fetched it once, and changed its policy to fail. Here is the configuration written by datur using the schema embedded in the installed executable:

cat(readLines(file.path(project, ".data.yaml")), sep = "\n")
#> version: 1
#> datasets:
#>   - id: customer_reference
#>     desc: Versioned customer reference data
#>     source:
#>       type: file
#>       path: upstream/customers.csv
#>     target: data/customers.csv
#>     policy: fail

Relative config, lock, source, and target paths are resolved from the child working directory. Set that directory without touching R’s global working directory:

original_r_working_directory <- getwd()
result <- datum_check(
  config = ".data.yaml",
  lock = ".data.lock.yaml",
  wd = project,
  timeout = 120,
  concurrency = 1,
  quiet = TRUE
)

stopifnot(identical(getwd(), original_r_working_directory))

Concurrency defaults to one because datum documents a race when datasets sharing a target directory are fetched concurrently.

3. Understand the actual JSON boundary

datur invokes flags before the subcommand:

datum --json --no-color --timeout 120s --concurrency 1 check

The process response is retained rather than copied into the documentation:

cat(jsonlite::prettify(result$process$stdout))
#> {
#>     "results": [
#>         {
#>             "id": "customer_reference",
#>             "status": "ok",
#>             "lock_fingerprint": "sha256:d7bfe0ea50821ba6bf2ad343bd22af2533351d7efbd389ac4594203ee7082268",
#>             "remote_fingerprint": "sha256:d7bfe0ea50821ba6bf2ad343bd22af2533351d7efbd389ac4594203ee7082268"
#>         }
#>     ]
#> }

The normalized object prints concisely:

print(result)
#> datum check: no changes across 1 target (11ms)
result$changed
#> [1] FALSE
result$status
#> [1] "unchanged"

The complete machine document remains available as result$raw, while documented normalized fields remain stable if datum adds JSON fields later.

4. Treat changed data as data

Change the local source after it has been fetched to exercise the fail policy with the installed datum version.

That exit code is not an R error because the JSON status proves this is a detected change:

writeLines("name,value\nalpha,2", file.path(project, "upstream", "customers.csv"))
result <- datum_check(wd = project, quiet = TRUE)
print(result)
#> datum check: 1 change across 1 target (10ms)
#> fail customer_reference
result$changed
#> [1] TRUE
result$process$status
#> [1] 1
as.data.frame(result)[, c("id", "status", "lock_fingerprint", "remote_fingerprint")]
#>                   id status
#> 1 customer_reference   fail
#>                                                          lock_fingerprint
#> 1 sha256:d7bfe0ea50821ba6bf2ad343bd22af2533351d7efbd389ac4594203ee7082268
#>                                                        remote_fingerprint
#> 1 sha256:442090a8c5365cde7d230997ed784ae5d2154de13f9bbd7ffd27aa7148c388ed

The same change under log has status stale and process status 0. Under update, status updated and process status 0 mean datum fetched the target and updated its lock record. All three statuses set result$changed to TRUE.

5. Build an incremental pipeline

result <- datum_check(wd = project, quiet = TRUE)
records <- as.data.frame(result)

changed <- records$status %in% c("updated", "stale", "fail")
changed_ids <- records$id[changed]

if ("customer_reference" %in% changed_ids) {
  source("R/rebuild-customer-features.R")
}

if ("exchange_rates" %in% changed_ids) {
  rmarkdown::render("reports/exposure.Rmd")
}

saveRDS(
  list(
    checked_at = result$checked_at,
    datum_version = as.character(result$datum_version),
    records = records
  ),
  "artifacts/data-check.rds"
)

Useful stable fields include:

  • changed: one non-missing logical value;
  • status: unchanged, changed, partial_failure, or error;
  • summary: named counts for total, changed, unchanged, failed, and skipped;
  • records: one base data-frame row per datum dataset;
  • checked_at and numeric duration in seconds;
  • datum_version and implicit schema_version 1;
  • process: redacted command metadata and captured streams.

6. Preserve partial results when a source fails

Datum continues across datasets. Add a missing local source to demonstrate that datur raises datur_cli_error but attaches the normalized partial result:

result <- tryCatch(
  datum_check(wd = project, quiet = TRUE),
  datur_cli_error = function(error) {
    if (is.null(error$result)) stop(error)
    message(conditionMessage(error))
    error$result
  }
)
#> datum returned usable results with operational failures.
#> ✖ One or more targets failed.
#> ℹ The partial check result is attached to this condition.

result$status
#> [1] "partial_failure"
subset(as.data.frame(result), status == "error", c("id", "message"))
#>            id
#> 2 unavailable
#>                                                                     message
#> 2 fingerprint: stat upstream/missing-source.json: no such file or directory

This supports a deliberate policy: use successful records, alert on failures, and decide whether the surrounding pipeline should stop.

7. Respond to typed conditions

All package errors inherit from datur_error and a specific subclass:

tryCatch(
  datum_check(wd = project, timeout = 30, quiet = TRUE),
  datur_not_found = function(error) {
    message("Install datum or configure DATUM_PATH")
  },
  datur_timeout = function(error) {
    message("Timed out after ", error$timeout, " seconds")
    print(error$partial_result)
  },
  datur_protocol_error = function(error) {
    message("Unsupported or malformed datum JSON")
    print(error$process)
  },
  datur_cli_error = function(error) {
    message("datum operational failure: ", conditionMessage(error))
  }
)

A change alone never raises a warning or error. Operational source failures, lock write failures, malformed JSON, incompatible versions, and R input errors remain distinguishable.

8. Use the low-level escape hatch intentionally

process <- datum_run(
  args = "--version",
  wd = project,
  timeout = 30,
  error_on_status = FALSE
)

print(process)
#> datum: status 0 (11ms)
process$stdout
#> [1] "datum v1.6.0\n"

datum_run() sends each args element directly to the executable. It does not construct a shell command. Named env values augment the inherited environment, and character or raw stdin is supplied through a private temporary file.

9. Know the side effects and security boundary

Even though its name is check, datum always rewrites lockfile timestamps. An update policy may fetch and replace targets, and source handlers may use the network or datum’s git cache. Run checks in a project where those effects are expected.

With datum 1.5.0 or newer, use ${NAME} references in .data.yaml to keep secrets and machine-specific values out of version control. Set those variables in the environment inherited by datum; unset references are configuration errors, while $${NAME} produces a literal ${NAME}. See the .data.yaml vignette for the complete expansion rules.

Environment substitution does not guarantee output redaction. Do not print credentials from command sources, and remember that an expanded value may appear in a downstream URL or error. datur redacts sensitive values passed explicitly through datum_run(env = ...), sensitive command arguments, and URL user info, but it cannot reliably identify every secret inherited from the R process. Prefer purpose-built authentication variables such as GIT_TOKEN when a source handler provides one.

For the exact reviewed boundary, including statuses and exit-code ambiguities, see docs/datum-cli-contract.md in the source repository.