V10 Import an ODCS contract
Use your current course session. Preparation and course runner · R script ↓
Optional deep dive. Enable only the options named in each block, after preparing its packages or services.
V10a Export an ODCS contract
Goal: Save a portable contract.
Prerequisites: H04; adapters, yaml; extras or gui.
The resulting ODCS document is also used in the YAML editor exercises.
training_step(
"V10a",
{
odcs_path <- file.path(training_root, "policies.contract.yaml")
if (!file.exists(odcs_path)) {
dataraft.adapters::dr_contract_odcs(policy_contract, path = odcs_path)
}
cat(
readLines(odcs_path),
sep = "
"
)
},
needs = c("H04"),
packages = c("dataraft.adapters", "yaml"),
enabled = training_options$extras || training_options$gui,
optional = TRUE
)Expected result: Readable YAML with contract metadata and columns.
Task: Why use the suffix .contract.yaml?
Show solution
It allows the extension to offer its contract editor.
V10 Import an ODCS contract
Goal: Execute the supported subset.
Prerequisites: V10a.
Unknown executable rules are not evaluated as arbitrary R. Unsupported constructs must be rejected explicitly.
training_step(
"V10",
{
imported_contract <- dataraft.adapters::dr_contract_from_odcs(odcs_path)
odcs_product <- dr_product(
"policies.odcs",
policies,
contract = imported_contract
)
print(dr_run(odcs_product, write = FALSE))
},
needs = c("V10a"),
enabled = training_options$extras || training_options$gui,
optional = TRUE
)Expected result: The saved contract is used for our data.
Task: Can dr_contract_yaml replace this roundtrip?
Show solution
No. That other export describes metadata; it is not an executable ODCS contract.