DRDataRaft/ docs
GitHub ↗

V17 Generate a targets graph

V17Adapters and additional tools3 steps

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.

V17a Create a project scaffold

Goal: Generate repeatable project files.

Prerequisites: extras; adapters.

The scaffold uses a new subdirectory and does not overwrite an existing project.

training_step(
  "V17a",
  {
    project_root <- file.path(training_root, "starter-project")
    dataraft.adapters::dr_init_project(
      project_root,
      name = "policies",
      renv = FALSE,
      targets = FALSE,
      connect = FALSE
    )
    print(list.files(project_root, recursive = TRUE))
  },
  packages = c("dataraft.adapters"),
  enabled = training_options$extras,
  optional = TRUE
)

Expected result: Files for a local project.

Task: Why leave renv=FALSE here?

Show solution

Package environments are a separate step; the course should not install packages implicitly.

V17b Define a file-based YAML project

Goal: Connect source, contract and target declaratively.

Prerequisites: V10a and V08a; adapters, yaml.

Referenced files use paths relative to the project file in the same course directory.

training_step(
  "V17b",
  {
    project_yaml_path <- file.path(training_root, "project.yaml")
    yaml::write_yaml(
      list(
        id = "policies.fileproject",
        contract = "policies.contract.yaml",
        source = "policies.csv",
        target = "yaml-rds"
      ),
      project_yaml_path
    )
    yaml_product <- dataraft.adapters::dr_project_yaml(project_yaml_path)
    print(dr_run(yaml_product, write = FALSE))
  },
  needs = c("V10a", "V08a"),
  packages = c("yaml", "dataraft.adapters"),
  enabled = training_options$extras,
  optional = TRUE
)

Expected result: An executable product based on declarative paths.

Task: Does loading the definition write the RDS target?

Show solution

No. That requires a writing run or dr_publish.

V17 Generate a targets graph

Goal: Hand orchestration to targets.

Prerequisites: H07; adapters, targets; extras.

Only generate the graph here. To use tar_make, place it in its own _targets.R. targets then provides caching and scheduling.

training_step(
  "V17",
  {
    policy_targets <- dataraft.adapters::dr_as_targets(policy_product)
    print(policy_targets)
  },
  needs = c("H07"),
  packages = c("dataraft.adapters", "targets"),
  enabled = training_options$extras,
  optional = TRUE
)

Expected result: A list of ordinary targets objects.

Task: Does targets detect every external API change?

Show solution

No. External sources need appropriate cues, often mode=always.

Search documentation

Search functions, packages and guides.