-
Notifications
You must be signed in to change notification settings - Fork 17
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
user case of tar_skip / tar_change, deal with empty targets #17
Comments
My recommendations are to:
library(targets)
dir.create("tmp")
writeLines("line1", "tmp/a")
writeLines("line2", "tmp/b")
tar_script({
library(tarchetypes)
options(crayon.enabled = FALSE)
list_files <- function(dir) {
files <- dir(dir, full.names = TRUE)
stopifnot(length(files) > 0L)
files
}
tar_pipeline(
tar_files(files, list_files("tmp")),
tar_target(lines, readLines(files), pattern = map(files))
)
})
tar_make()
#> ● run target files_files
#> ● run branch files_98d8cd68
#> ● run branch files_33ec7836
#> ● run branch lines_3ac9849f
#> ● run branch lines_e2330cb9
tar_read(lines)
#> [1] "line1" "line2" Created on 2020-10-26 by the reprex package (v0.3.0) There are workarounds that do not require library(targets)
dir.create("tmp")
writeLines("line1", "tmp/a")
writeLines("line2", "tmp/b")
tar_script({
options(crayon.enabled = FALSE)
list_files <- function(dir) {
files <- dir(dir, full.names = TRUE)
stopifnot(length(files) > 0L)
files
}
tar_pipeline(
tar_target(paths, list_files("tmp"), cue = tar_cue(mode = "always")),
tar_target(files, paths, pattern = map(paths), format = "file"),
tar_target(lines, readLines(files), pattern = map(files))
)
})
tar_make()
#> ● run target paths
#> ● run branch files_fe460508
#> ● run branch files_dcad1233
#> ● run branch lines_ef9c4ed9
#> ● run branch lines_bc722500 Created on 2020-10-26 by the reprex package (v0.3.0) |
Thanks a lot William for your incredible reactivity and helpful comments. I will try both approaches tomorrow. |
I ended using |
Glad to hear it's working for you. |
Prework
Description
Hi,
first of all thank a lot for the fabulous work you are doing, I was using slighly
drake
(and actually posted a relevant issue that you solved.Now I moved to
targets
and I like it a lot. My workflow is to track new lectures/tutorials in dedicated folders and build a website for teaching. The part that is not working is how to deal with empty targets.Here is a small example of something that is working, I am using
tar_change
to track the apparition of new files, then we computemd5sum
and do stuff.Created on 2020-10-26 by the reprex package (v0.3.0)
Reproducible example
Now comes the issue, if we don't have any file in the folder, I get
callr subprocess failed: cannot branch over empty target
.To control for this, I tried to use
tar_skip()
that seems to be relevant for this user case:Created on 2020-10-26 by the reprex package (v0.3.0)
Desired result
I can see that the rule
files
was indeed cancel as expected. But it didn't prevent the following steps to be processed.I am a little lost now for preventing dependent branches to be performed.
Many thanks in advance for your kind help
Diagnostic information
sessionInfo()
orreprex(si = TRUE)
.Created on 2020-10-26 by the reprex package (v0.3.0)
Session info
traceback()
orrlang::trace_back()
.tarchetypes
currently installed.packageDescription("tarchetypes")$GithubSHA1
shows you this.tarchetypes
shasum commit:585bce24595d672537d2fe19c4540350b81a675e
The text was updated successfully, but these errors were encountered: