-
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
Transformation depends on other targets #1199
Comments
Static branching has unavoidable limitations, and I am trying to document them in https://books.ropensci.org/drake/static.html#limitations-of-grouping-variables. You are running into the issue because you are using the library(drake)
plan <- drake_plan(
data = target(
get_data(radar, month),
transform = cross(radar = !!radars, month = !!months)
),
to_cross = target(
list(data),
transform = combine(data, .by = radar)
),
problem = target(
list(to_cross, season),
transform = cross(to_cross, season = !!seasons)
),
separate = target(
list(radar, season),
transform = map(radar = !!radar_seasons$radar, season = !!radar_seasons$season)
),
transform = FALSE
)
plot(plan) Created on 2020-03-02 by the reprex package (v0.3.0) To fix the issue, define new grouping variables for library(drake)
library(dplyr)
#>
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#>
#> filter, lag
#> The following objects are masked from 'package:base':
#>
#> intersect, setdiff, setequal, union
radars <- c("radar1", "radar2")
seasons <- c("season1", "season2")
months <- c(1, 2)
radar_seasons <- expand.grid(radar2 = radars, season2 = seasons, stringsAsFactors = FALSE)
plan <- drake_plan(
data = target(
get_data(radar, month),
transform = cross(radar = !!radars, month = !!months)
),
to_cross = target(
list(data),
transform = combine(data, .by = radar)
),
problem = target(
list(to_cross, season),
transform = cross(to_cross, season = !!seasons)
),
separate = target(
list(radar2, season2),
transform = map(.data = !!radar_seasons)
),
trace = TRUE
)
select(plan, target, radar, radar2)
#> # A tibble: 14 x 3
#> target radar radar2
#> <chr> <chr> <chr>
#> 1 data_radar1_1 "\"radar1\"" <NA>
#> 2 data_radar2_1 "\"radar2\"" <NA>
#> 3 data_radar1_2 "\"radar1\"" <NA>
#> 4 data_radar2_2 "\"radar2\"" <NA>
#> 5 to_cross_radar1 "\"radar1\"" <NA>
#> 6 to_cross_radar2 "\"radar2\"" <NA>
#> 7 problem_season1_to_cross_radar1 "\"radar1\"" <NA>
#> 8 problem_season2_to_cross_radar1 "\"radar1\"" <NA>
#> 9 problem_season1_to_cross_radar2 "\"radar2\"" <NA>
#> 10 problem_season2_to_cross_radar2 "\"radar2\"" <NA>
#> 11 separate_radar1_season1 <NA> "\"radar1\""
#> 12 separate_radar2_season1 <NA> "\"radar2\""
#> 13 separate_radar1_season2 <NA> "\"radar1\""
#> 14 separate_radar2_season2 <NA> "\"radar2\"" Created on 2020-03-02 by the reprex package (v0.3.0) |
Reopening. The solution to this is actually pretty simple on reflection. We just need to restrict static transforms so they only use the upstream part of the plan. Then |
But it is still risky to define the same grouping variables twice. After the patch, you will be able do it in two different disconnected parts of the plan, but not in plans like the one from https://books.ropensci.org/drake/static.html#limitations-of-grouping-variables. |
Please note this is code derived from a much bigger plan I tried to minimize it as much as possible (that is why it looks a bit clunky). I create the plan as shown below. Everything works fine as long as the target
separate
is not included.But as soon as the target
separate
is included (second transformation below) the transformation fails for the columnradar
. Theproblem
target gets the sameradar
attribute (see "the problem" comment). I expected this to be the same as before. I would like to bring these later together hence the replication of names fromradarSeasons
.Created on 2020-03-02 by the reprex package (v0.3.0)
The text was updated successfully, but these errors were encountered: