0

I have a plan of a general form like the one below My real plan is more complex and I've been unable to reproduce this error in a toy example. Has anyone seen a problem like this and do you have any ideas about what might be causing it? The plan takes a set of model results, produces a summary some plots and report for each.

dplan <- drake_plan(
    models = target(
        read_models(model),
        map(model = c("a","b","c"))
    ),
    dep1 = target(
        summarise_models(models),
        map(models)
    ),
    dep2 = target(
        plot_models(models),
        map(models)
    ),
    report = target(
        write_report(dep1, dep2),
        map(dep1, dep2)
    )
)

The targets dep1_a-c and dep2_a-c are generated but there is an issue with dep2 dep2_a-c appears in the plot but report_a-c are not shown as depending on them as they are on dep1_a-c respectively. That is to say dep1_a is generated and report_a is dependent on it and whilst dep2_a is generated report_a does not 'beleive' it depends on dep2_a despite dep2 being in the map call in the report target.

The error I get when I run make is an error of the form: $error$message: object 'dep2' not found $error$calls:base::eval(quote(...and the quote shows that dep2 is not evaluating to dep2_a etc. in the call it is just bare dep2 which of course does exist as a target only dep2_a-c do - I'm very confused by why this is happening with one target and not the others :(

My real example has several dependencies and I have equivalents of dep2 in my example that are almost identical in output, they return the same type of object mapped over the same list but for some reason, their targets are not evaluated properly in when making report target

I've tried running clean(destroy = TRUE) and rerunning from scratch with no luck

landau
  • 5,636
  • 1
  • 22
  • 50
Richard J. Acton
  • 885
  • 4
  • 17

1 Answers1

0

For future projects, I recommend building up the plan gradually to avoid things getting out of hand. It's easy to get overwhelmed if you write all the targets in the plan all at once. Users should:

  1. Write 1 or 2 targets.
  2. Check the plan, e.g vis_drake_graph() or plot(plan).
  3. Run make(plan).
  4. Inspect the output with readd() and/or loadd() (exploratory analysis).
  5. Repeat.

For an example of this iterative process, see https://wlandau.github.io/learndrake.

There is nothing wrong with the plan you wrote above, so it's hard to speculate about what could be wrong with your actual plan. But the good news is that you should be able to troubleshoot without running make() at all. vis_drake_graph() can tell you right away if some dependency relationships are incorrectly specified. Here is what the graph looks like for your example plan.

library(drake)
plan <- drake_plan(
  models = target(
    read_models(model),
    map(model = c("a", "b"))
  ),
  dep1 = target(
    summarise_models(models),
    map(models, .id = model)
  ),
  dep2 = target(
    plot_models(models),
    map(models, .id = model)
  ),
  report = target(
    write_report(dep1, dep2),
    map(dep1, dep2, .id = model)
  )
)
vis_drake_graph(plan)

enter image description here

If dep2 is not expanded correctly, this is what the graph would look like:

library(drake)
plan <- drake_plan(
  models = target(
    read_models(model),
    map(model = c("a", "b"))
  ),
  dep1 = target(
    summarise_models(models),
    map(models, .id = model)
  ),
  dep2 = target(
    plot_models(models),
    map(models, .id = model)
  ),
  report = target(
    write_report(dep1, dep2),
    map(dep1, dep2, .id = model)
  )
)
vis_drake_graph(plan)

enter image description here

landau
  • 5,636
  • 1
  • 22
  • 50
  • Thanks for the careful response @landau, I know this is kind of a tricky one answer well. I was indeed building up my plan step-by-step having taken the guidance of your excellent manual. The topology you plot out is exactly what I see. I had a working plan Like the one in my example with both `dep1` and `dep2` working fine and essentially copied `dep1` and `dep2` from my example to make two new sets of targets, with changed `summarise_models` and `plot_models` functions. I added the new targets to the report, then the connections of the new target's to the report didn't show up the graph. – Richard J. Acton Nov 13 '20 at 09:28
  • Static branching only operates on the plan, not the source files of R Markdown reports. To load a target into a report, one needs to anticipate what the target name is going to be. – landau Nov 13 '20 at 11:53