Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Target descriptions #1236

Merged
merged 22 commits into from
Feb 19, 2024
Merged

Target descriptions #1236

merged 22 commits into from
Feb 19, 2024

Conversation

wlandau
Copy link
Collaborator

@wlandau wlandau commented Feb 19, 2024

Prework

Related GitHub issues and pull requests

Summary

tar_target() gains a new description argument for free-form text to describe what the target is about.

# _targets.R
library(targets)
list(
  tar_target(
    name = data,
    command = airquality,
    description = "airquality dataset from base R"
  ),
  tar_target(
    name = model1,
    command = broom::tidy(lm(Ozone ~ Temp, data = data)),
    description = "model of ozone against temperature (degrees F)"
  ),
  tar_target(
    name = model2,
    command = broom::tidy(lm(Ozone ~ Wind, data = data)),
    description = "model of ozone against wind speed (mph)"
  )
)

The descriptions show up in tar_manifest(), tar_network(), tar_glimpse(), tar_visnetwork(), and tar_mermaid().

library(targets)
tar_mermaid()
graph LR
  style Legend fill:#FFFFFF00,stroke:#000000;
  style Graph fill:#FFFFFF00,stroke:#000000;
  subgraph Legend
    direction LR
    x0a52b03877696646([""Outdated""]):::outdated --- xbf4603d6c2c2ad6b([""Stem""]):::none
  end
  subgraph Graph
    direction LR
    xb7119b48552d1da3(["data<br>airquality dataset from base R"]):::outdated --> xd2415809dfccb1c9(["model1<br>model of ozone against temperature (degrees F)"]):::outdated
    xb7119b48552d1da3(["data<br>airquality dataset from base R"]):::outdated --> x5e90f77e4394a7c0(["model2<br>model of ozone against wind speed (mph)"]):::outdated
  end
  classDef outdated stroke:#000000,color:#000000,fill:#78B7C5;
  classDef none stroke:#000000,color:#000000,fill:#94a4ac;
  linkStyle 0 stroke-width:0px;
Loading

tar_described_as() is a wrapper around tidyselect::any_of() to allow grouping of different targets based on the description rather than the name.

tar_manifest(names = tar_described_as(starts_with("model"))) # Does not show the dataset.
#> # A tibble: 2 × 3
#>   name   command                                    description                               
#>   <chr>  <chr>                                      <chr>                                     
#> 1 model1 broom::tidy(lm(Ozone ~ Temp, data = data)) model of ozone against temperature (degre…
#> 2 model2 broom::tidy(lm(Ozone ~ Wind, data = data)) model of ozone against wind speed (mph) 
tar_make(names = tar_described_as(contains("dataset"))) # Does not run the models.
#> ▶ dispatched target data
#> ● completed target data [0.001 seconds]
#> ▶ ended pipeline [0.055 seconds]

FYI @tjmahr, @noamross, @mattmoo

@wlandau wlandau merged commit 78a653f into main Feb 19, 2024
15 checks passed
@wlandau wlandau deleted the 1230 branch February 19, 2024 20:29
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant