-
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
How to create a jagged cross() transform #697
Comments
Another nice one for the FAQ. Fortunately, this is straightforward if you create your own grid in advance and then use library(drake)
library(tidyverse)
grid <- crossing(
group = c("G1", "G2"),
rep = c("R1", "R2", "R3", "R4", "R5", "R6")
) %>%
filter(!(group == "G2" & rep %in% c("R5", "R6")))
drake_plan(
s_load = target(
load_csv(group, rep),
transform = map(
group = !!grid$group,
rep = !!grid$rep
)
)
)
#> # A tibble: 10 x 2
#> target command
#> <chr> <chr>
#> 1 s_load_.G1._.R1. "load_csv(\"G1\", \"R1\")"
#> 2 s_load_.G1._.R2. "load_csv(\"G1\", \"R2\")"
#> 3 s_load_.G1._.R3. "load_csv(\"G1\", \"R3\")"
#> 4 s_load_.G1._.R4. "load_csv(\"G1\", \"R4\")"
#> 5 s_load_.G1._.R5. "load_csv(\"G1\", \"R5\")"
#> 6 s_load_.G1._.R6. "load_csv(\"G1\", \"R6\")"
#> 7 s_load_.G2._.R1. "load_csv(\"G2\", \"R1\")"
#> 8 s_load_.G2._.R2. "load_csv(\"G2\", \"R2\")"
#> 9 s_load_.G2._.R3. "load_csv(\"G2\", \"R3\")"
#> 10 s_load_.G2._.R4. "load_csv(\"G2\", \"R4\")" Created on 2019-01-31 by the reprex package (v0.2.1.9000) |
Nice! Thanks for the solution. |
Sounds like #685, which many people have requested. In But if the files you mention are all available before you write the plan, then yes, you can write a plan whose target names are automatically generated. library(drake)
files <- list.files("dir")
plan <- drake_plan(s_load = target(load_csv(file), transform = map(file = !!files))) |
#720 will make custom grids easier. Check this out: library(drake)
library(tidyverse)
grid <- crossing(
group = c("G1", "G2"),
rep = c("R1", "R2", "R3", "R4", "R5", "R6")
) %>%
filter(!(group == "G2" & rep %in% c("R5", "R6")))
drake_plan(
s_load = target(
load_csv(group, rep),
transform = map(.data = !!grid)
)
)
#> # A tibble: 10 x 2
#> target command
#> <chr> <expr>
#> 1 s_load_.G1._.R1. load_csv("G1", "R1")
#> 2 s_load_.G1._.R2. load_csv("G1", "R2")
#> 3 s_load_.G1._.R3. load_csv("G1", "R3")
#> 4 s_load_.G1._.R4. load_csv("G1", "R4")
#> 5 s_load_.G1._.R5. load_csv("G1", "R5")
#> 6 s_load_.G1._.R6. load_csv("G1", "R6")
#> 7 s_load_.G2._.R1. load_csv("G2", "R1")
#> 8 s_load_.G2._.R2. load_csv("G2", "R2")
#> 9 s_load_.G2._.R3. load_csv("G2", "R3")
#> 10 s_load_.G2._.R4. load_csv("G2", "R4") Created on 2019-02-07 by the reprex package (v0.2.1.9000) |
I am hoping to do a
cross()
transform but I wouldn't want a complete cross product - rather a jagged version instead, e.g.:For example, my group G1 has rep R1-R6, but G2 only has R1-R4 which is missing R5-R6.
My function
load_csv
is searching for input files to read, in this caseGx_Ry.csv
for example, but I don't haveG2_R5.csv
andG2_R6.csv
and so it fails with files not found for those two targets.Any recommendations would be appreciated, thanks!
The text was updated successfully, but these errors were encountered: