Skip to content
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

Wildcards in trigger condition are not expanded #528

Closed
idavydov opened this issue Oct 4, 2018 · 4 comments
Closed

Wildcards in trigger condition are not expanded #528

idavydov opened this issue Oct 4, 2018 · 4 comments
Assignees

Comments

@idavydov
Copy link

idavydov commented Oct 4, 2018

As far as I understand, one of the motivations for the new trigger interface (#473) was the ability to write a code like this:

drake_plan(
  target1 = ...,
  target2 = target(
    ...,
    trigger=trigger(
      condition = is_small_enough(target1)
    )
  )
)

This seems to work fine, however evaluate_plan seems to ignore trigger while expanding wildcards:

library(drake)
library(magrittr)
pkgconfig::set_config("drake::strings_in_dots" = "literals")


plan <- drake_plan(
  a = n__ + 1,
  b = target(
    a_n__ + 2,
    trigger=trigger(condition=a_n__ > 0)
  )
) %>% evaluate_plan(list(n__=1:2))

plan

That's the output:

# A tibble: 4 x 3
  target command trigger                       
* <chr>  <chr>   <chr>                         
1 a_1    1 + 1   NA                            
2 a_2    2 + 1   NA                            
3 b_1    a_1 + 2 trigger(condition = a_n__ > 0)
4 b_2    a_2 + 2 trigger(condition = a_n__ > 0)

I expected to have this:

3 b_1    a_1 + 2 trigger(condition = a_1 > 0)
4 b_2    a_2 + 2 trigger(condition = a_2 > 0)

A more general question

Please let me know if I should open a separate issue or ask on stackoverflow.

I would like to "kill" certain branches based on their input. E.g., if for some input data I haven't received enough results, I do not want to continue.

It seems that trigger(condition=...) won't help because dependency reasoning has a higher priority over condition and trigger(depend=FALSE, condition=...) will disable dependency monitoring for the target completely.

The easiest workaround I see now is to return a special value (e.g. NULL). And in this case all downstream commands would have to check for a special value.

plan <- drake_plan(
  a = rnorm(1),
  b = if (a>0) sqrt(a) else NULL,
  c = if (is.null(b)) NULL else b+1,
  d = if (is.null(c)) NULL else c+1,
)

Any suggestions?

@wlandau wlandau self-assigned this Oct 4, 2018
@wlandau
Copy link
Member

wlandau commented Oct 4, 2018

Wildcards in triggers

evaluate_plan() has a columns argument. Here, you can list all the columns in the plan where you want drake to look for wildcards.

library(drake)
library(magrittr)
pkgconfig::set_config("drake::strings_in_dots" = "literals")
drake_plan(
  a = n__ + 1,
  b = target(
    a_n__ + 2,
    trigger=trigger(condition=a_n__ > 0)
  )
) %>%
  evaluate_plan(
    rules = list(n__ = 1:2),
    columns = c("command", "trigger")
  )
#> # A tibble: 4 x 3
#>   target command trigger                     
#> * <chr>  <chr>   <chr>                       
#> 1 a_1    1 + 1   <NA>                        
#> 2 a_2    2 + 1   <NA>                        
#> 3 b_1    a_1 + 2 trigger(condition = a_1 > 0)
#> 4 b_2    a_2 + 2 trigger(condition = a_2 > 0)

The more general question

I like your workaround. When I designed triggers, I did not anticipate the need to explicitly suppress a target. Maybe there should be a suppress trigger analogous to the condition trigger. I do not know, and I will think about it.

@idavydov
Copy link
Author

idavydov commented Oct 4, 2018

Thanks! Totally missed columns. My bad.

@wlandau
Copy link
Member

wlandau commented Oct 4, 2018

No worries. drake is complicated.

@wlandau
Copy link
Member

wlandau commented Oct 4, 2018

Also, I tend to focus a lot more on the issue tracker than StackOverflow. I try to check the questions tagged with drake-r-package, but even so, I end up missing more than I would like.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants