Skip to content

Acting on branches in sequence in pairs of two in downstream target #719

Closed Answered by wlandau
januz asked this question in Help
Discussion options

You must be logged in to vote

I recommend something like this: #615. In your case, you could first identify pairs of files, then track them with format = "file", then read in the contents. Sketch:

# _targets.R file:
library(targets)  

# Set up the files if they do not already exist (for the sake of this reprex)
fs::dir_create("dir")
files <- c("dir/file1.txt", "dir/file2.txt", "dir/file3.txt", "dir/file4.txt")
purrr::walk(files, ~if (!file.exists(.x)) writeLines(basename(.x), .x))

files <- list.files("dir", full.names = TRUE) # continuously refresh as a global variable here

list(
  tar_target(
    pair_files,
    tibble::tibble(
      first = as.character(na.omit(dplyr::lag(files, n = 2))), # as.character() removes…

Replies: 1 comment 8 replies

Comment options

You must be logged in to vote
8 replies
@januz
Comment options

@januz
Comment options

@wlandau
Comment options

@januz
Comment options

@wlandau
Comment options

Answer selected by januz
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help
Labels
None yet
2 participants