-
Help
Descriptionlapply, map, etc.. pass a vector argument to the function vector <- 1:3
list <- as.list(vector)
vapply(list, is.list, FUN.VALUE = logical(1))
#> [1] FALSE FALSE FALSE In targets, map passes each elements as a one-length list targets::tar_dir({
targets::tar_script({
list(
targets::tar_target(paths_list, as.list(1:3)),
targets::tar_target(
x,
is.list(paths_list),
pattern = map(paths_list)
)
)
})
targets::tar_make()
targets::tar_read(x)
})
#> ▶ dispatched target paths_list
#> ● completed target paths_list [0.001 seconds]
#> ▶ dispatched branch x_0a69e4b5
#> ● completed branch x_0a69e4b5 [0 seconds]
#> ▶ dispatched branch x_fe432996
#> ● completed branch x_fe432996 [0.001 seconds]
#> ▶ dispatched branch x_57ce207a
#> ● completed branch x_57ce207a [0 seconds]
#> ● completed pattern x
#> ▶ completed pipeline [0.118 seconds]
#> x_0a69e4b5 x_fe432996 x_57ce207a
#> TRUE TRUE TRUE To get the equivalent, you need to extract the element targets::tar_dir({
targets::tar_script({
list(
targets::tar_target(paths_list, as.list(1:3)),
targets::tar_target(
x,
is.list(paths_list[[1]]),
pattern = map(paths_list)
)
)
})
targets::tar_make()
targets::tar_read(x)
})
#> ▶ dispatched target paths_list
#> ● completed target paths_list [0.001 seconds]
#> ▶ dispatched branch x_0a69e4b5
#> ● completed branch x_0a69e4b5 [0 seconds]
#> ▶ dispatched branch x_fe432996
#> ● completed branch x_fe432996 [0.001 seconds]
#> ▶ dispatched branch x_57ce207a
#> ● completed branch x_57ce207a [0.001 seconds]
#> ● completed pattern x
#> ▶ completed pipeline [0.117 seconds]
#> x_0a69e4b5 x_fe432996 x_57ce207a
#> FALSE FALSE FALSE I expected map to apply the command to each element of |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
What happens if you set |
Beta Was this translation helpful? Give feedback.
-
Ah, sorry, I had misunderstood how the This now works. targets::tar_dir({
targets::tar_script({
list(
targets::tar_target(paths_list, as.list(1:3), iteration = "list"),
targets::tar_target(
x,
is.list(paths_list),
pattern = map(paths_list)
)
)
})
targets::tar_make()
targets::tar_read(x)
})
#> ▶ dispatched target paths_list
#> ● completed target paths_list [0.001 seconds]
#> ▶ dispatched branch x_bed6a16d
#> ● completed branch x_bed6a16d [0.001 seconds]
#> ▶ dispatched branch x_36a089b4
#> ● completed branch x_36a089b4 [0 seconds]
#> ▶ dispatched branch x_5d98722e
#> ● completed branch x_5d98722e [0 seconds]
#> ● completed pattern x
#> ▶ completed pipeline [0.116 seconds]
#> x_bed6a16d x_36a089b4 x_5d98722e
#> FALSE FALSE FALSE Created on 2024-01-26 with reprex v2.0.2 |
Beta Was this translation helpful? Give feedback.
Ah, sorry, I had misunderstood how the
iteration
argument worked. I though it determined how thepattern
did the iteration, but instead is a property of how will the target be iterated with map.This now works.