wlandau/targets-tutorial

4-files.Rmd

wlandau opened this issue · 3 comments

Prework

  • I understand and agree to the code of conduct.
  • I understand and agree to the contributing guidelines.
  • Be considerate of the maintainer's time and make it as easy as possible to troubleshoot any problems you identify. Read here and here to learn about minimal reproducible examples. Format your code according to the tidyverse style guide to make it easier for others to read.

Only literate programming remains.

Need to explain how to correctly map over file targets. This way is wrong:

options(crayon.enabled = FALSE, tidyverse.quiet = TRUE)
library(targets)
library(tidyverse)
write_csv(tibble(x1 = 1, x2 = 1), "a.csv")
write_csv(tibble(x1 = 1, x2 = 1), "b.csv")
tar_script({
  options(crayon.enabled = FALSE, tidyverse.quiet = TRUE)
  library(readr)
  tar_pipeline(
    tar_target(paths, c("a.csv", "b.csv"), format = "file"),
    tar_target(data, read_csv(paths, col_types = "dd"), pattern = map(paths))
  )
})
tar_make()
#> ● run target paths
#> ● run branch data_5085a9cd
#> ● run branch data_b7dcad9d
write_csv(tibble(x1 = 2, x2 = 2), "b.csv")
tar_make()
#> ● run target paths
#> ✓ skip branch data_5085a9cd
#> ✓ skip branch data_b7dcad9d

Created on 2020-08-07 by the reprex package (v0.3.0)

Done.