0

I'm trying to understand how to use knitr_out, file_out and vis_drake_graph properly in drake.

I have two questions.

Q1: Usage of knitr_out and file_out to create markdown reports

While a code like this works correctly for one of my smaller projects:

make_hyp_data_aggregated_report <- function() {
        render(
                input = knitr_in("rmd/hyptest-is-data-being-aggregated.Rmd"),
                output_file = file_out("~/projectname/reports/01-hyp-test.html"),
                quiet = TRUE
        )
}

plan <- drake_plan(
        ...
        ...
        hyp_data_aggregated_report = make_hyp_data_aggregated_report()
        ...
        ...
) 

enter image description here

Exactly similar code in my large project (with ~10+ reports) doesn't work exactly right. i.e., while the reports get built, the knitr_in objects don't get displayed as the blue squares in the graph using drake::vis_drake_graph() in my large project.

Both projects use the drake::loadd(....) within the markdown to get the objects from cache.

Is there some code in vis_drake_graph that removes these squares once the graph gets busy?

Q2: file_out objects in vis_drake_graph

Is there a way to display the file_out objects themselves as circles/squares in vis_drake_graph?

Q3: packages showing up in vis_drake_graph

Is there a way to avoid vis_drake_graph from printing the packages explicitly? (Basically anything with the ::)

enter image description here

Rahul
  • 2,579
  • 1
  • 13
  • 22

1 Answers1

1

Q1

Every literal file path needs its own knitr_in() or file_out(). If you have one function with one knitr_in(), even if you use the function multiple times, that still only counts as one file path. I recommend writing these keywords at the plan level, e.g.

plan <- drake_plan(
  r1 = render(knitr_in("report1.Rmd"), output_file = file_out("report1.html")),
  r2 = render(knitr_in("report2.Rmd"), output_file = file_out("report2.html")),
  r3 = render(knitr_in("report3.Rmd"), output_file = file_out("report3.html"))
)

Q2

They should appear unless you set show_output_files = FALSE in vis_drake_graph().

Q3

No, but if it's any consolation, I do regret the decision to track namespaced functions and objects at all in drake. drake's approach is fundamentally suboptimal for tracking packages, and I plan to get rid of it if there ever comes time for a round of breaking changes. Otherwise, there is no way to get rid of it except vis_drake_graph(targets_only = TRUE), which also gets rid of all the imports in the graph.

landau
  • 5,636
  • 1
  • 22
  • 50
  • how's this idea to address Q3... https://gitlab.com/snippets/1902252 – Rahul Oct 08 '19 at 16:05
  • Sure, or the `subset` argument of `vis_drake_graph()`. – landau Oct 08 '19 at 19:08
  • Could we add this as a feature to `vis_drake_graph`? Something like `remove_pkg_imports = TRUE` ? – Rahul Oct 08 '19 at 19:23
  • Sorry, I do not think enough people will use it. Not the sort of thing I would hard-code in an exported function. – landau Oct 08 '19 at 19:35
  • Gotcha. Our team feels the need for it since we're trying to use `drake` along with package development. So all entire codebase has explicit function calls. I'll just make a fork and modify things for our team. – Rahul Oct 08 '19 at 19:46