-
Notifications
You must be signed in to change notification settings - Fork 129
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
file_in/out within dynamic targets #1140
Comments
I knew someone would ask for this eventually. I did consider it, but it would be an arduous uphill battle against the original design of If you put all your sub-folders under one monolithic folder, you can achieve a similar effect. drake_plan(
x = settings_vector,
y = target(
visualize(x, figures = file_out("all_figures")),
dynamic = map(x)
)
) It is not perfect because any change to any figure in library(drake)
fs::dir_create("all_figures")
write_file <- function(x, dir) {
dir <- file.path(dir, x)
writeLines("lines", dir)
}
plan <- drake_plan(
file_names = c(1L, 2L, 3L, 4L),
write_files = target(
write_file(file_names, dir = file_out("all_figures")),
dynamic = map(file_names)
)
)
make(plan)
#> target file_names
#> dynamic write_files
#> subtarget write_files_0b3474bd
#> subtarget write_files_b2a5c9b8
#> subtarget write_files_71f311ad
#> subtarget write_files_98cf3c11
#> aggregate write_files
# Break a file
writeLines("broken", "all_figures/1")
# Rebuild all the sub-targets
make(plan)
#> dynamic write_files
#> subtarget write_files_0b3474bd
#> subtarget write_files_b2a5c9b8
#> subtarget write_files_71f311ad
#> subtarget write_files_98cf3c11
#> aggregate write_files
# Plan for a different set of output files
plan <- drake_plan(
file_names = c(1L, 2L, 5L, 6L),
write_files = target(
write_file(file_names, dir = file_out("all_figures")),
dynamic = map(file_names)
)
)
# Rebuild only some of the sub-targets
make(plan)
#> target file_names
#> dynamic write_files
#> subtarget write_files_0a86c9cb
#> subtarget write_files_cb15b01f
#> aggregate write_files
# Plan for *all* the files built so far.
plan <- drake_plan(
file_names = c(1L, 2L, 3L, 4L, 5L, 6L),
write_files = target(
write_file(file_names, dir = file_out("all_figures")),
dynamic = map(file_names)
)
)
# The directory gets re-hashed,
# but no sub-targets need to build.
make(plan)
#> target file_names
#> dynamic write_files
#> aggregate write_files Created on 2020-01-20 by the reprex package (v0.3.0) Related: #1127. |
Hmm... maybe that reprex is not such a good way to do things. It is possible to trick library(drake)
fs::dir_create("all_figures")
write_file <- function(x, dir) {
dir <- file.path(dir, x)
writeLines("lines", dir)
}
plan <- drake_plan(
file_names = c(1L, 2L, 3L, 4L),
write_files = target(
write_file(file_names, dir = file_out("all_figures")),
dynamic = map(file_names)
)
)
make(plan)
#> target file_names
#> dynamic write_files
#> subtarget write_files_0b3474bd
#> subtarget write_files_b2a5c9b8
#> subtarget write_files_71f311ad
#> subtarget write_files_98cf3c11
#> aggregate write_files
# Change what the files are supposed to contain
write_file <- function(x, dir) {
dir <- file.path(dir, x)
writeLines("lines2", dir)
}
plan <- drake_plan(
file_names = c(1L, 2L),
write_files = target(
write_file(file_names, dir = file_out("all_figures")),
dynamic = map(file_names)
)
)
make(plan)
#> target file_names
#> dynamic write_files
#> subtarget write_files_0b3474bd
#> subtarget write_files_b2a5c9b8
#> aggregate write_files
# Go back to all the files.
plan <- drake_plan(
file_names = c(1L, 2L, 3L, 4L),
write_files = target(
write_file(file_names, dir = file_out("all_figures")),
dynamic = map(file_names)
)
)
make(plan)
#> target file_names
#> dynamic write_files
#> aggregate write_files
# wrong contents
readLines("all_figures/3")
#> [1] "lines" Created on 2020-01-20 by the reprex package (v0.3.0) |
For what it's worth, |
For anyone else looking for a workaround regarding
|
Update: I suggest taking a look at #1178. |
Prework
drake
's code of conduct.Proposal
Hi Will,
Will
file_in()
andfile_out()
be supported within dynamic targets in the future? Or is this too difficult to implement? I am writing figures to different sub folders which are defined within the dynamic target and the files are not saved to one directory (so I cannot simply track the entire directory).Thanks in advance,
Jenny
The text was updated successfully, but these errors were encountered: